Skip to content

Commit

Permalink
Docs improved
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham16g committed Jul 14, 2022
1 parent 32cf33e commit f5367e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/src/image_file.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import 'dart:typed_data';

/// Store the image data and other information.
class ImageFile {
final String name;
final String extension;
final Uint8List? bytes;
final String? path;

/// returns true if image has path. (For web path is not available)
bool get hasPath => path != null;

/// returns size of bytes if image has bytes, else 0.
int get size => bytes?.length ?? 0;

ImageFile(
Expand Down
14 changes: 13 additions & 1 deletion lib/src/multi_image_picker_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:flutter/foundation.dart';

import '../multi_image_picker_view.dart';

/// Controller for the [MultiImagePickerView].
/// This controller contains all them images that the user has selected.
class MultiImagePickerController with ChangeNotifier {
final List<String> allowedImageTypes;
final int maxImages;
Expand All @@ -15,15 +17,22 @@ class MultiImagePickerController with ChangeNotifier {
}

final List<ImageFile> _images = <ImageFile>[];

/// Returns [Iterable] of [ImageFile] that user has selected.
Iterable<ImageFile> get images => _images;

/// Returns true if user has selected no images.
bool get hasNoImages => _images.isEmpty;

/// manually pick images. i.e. on click on external button.
/// this method open Image picking window.
/// It returns [Future] of [bool], true if user has selected images.
Future<bool> pickImages() async {
FilePickerResult? result = await FilePicker.platform.pickFiles(
allowMultiple: true,
type: FileType.custom,
allowedExtensions: allowedImageTypes);
if (result != null) {
if (result != null && result.files.isNotEmpty) {
_addImages(result.files
.where((e) =>
e.extension != null &&
Expand All @@ -47,6 +56,7 @@ class MultiImagePickerController with ChangeNotifier {
}
}

/// Manually re-order image, i.e. move image from one position to another position.
void reOrderImage(int oldIndex, int newIndex, {bool notify = true}) {
final oldItem = _images.removeAt(oldIndex);
oldItem.size;
Expand All @@ -56,6 +66,7 @@ class MultiImagePickerController with ChangeNotifier {
}
}

/// Manually remove image from list.
void removeImage(ImageFile imageFile) {
_images.remove(imageFile);
notifyListeners();
Expand All @@ -69,3 +80,4 @@ class MultiImagePickerController with ChangeNotifier {
print(_images);
}
}

7 changes: 4 additions & 3 deletions lib/src/multi_image_picker_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter_reorderable_grid_view/widgets/reorderable_builder.dart';

import '../multi_image_picker_view.dart';

/// Widget that holds entire functionality of the [MultiImagePickerView].
class MultiImagePickerView extends StatefulWidget {
const MultiImagePickerView(
{Key? key,
Expand Down Expand Up @@ -249,14 +250,14 @@ class _ItemView extends StatelessWidget {
margin: const EdgeInsets.all(4),
padding: const EdgeInsets.all(3),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
color: Colors.white.withOpacity(0.4),
shape: BoxShape.circle,
),
child: Image.asset(
'assets/close-48.png',
package: 'multi_image_picker_view',
height: 20,
width: 20,
height: 18,
width: 18,
)),
onTap: () {
onDelete(file);
Expand Down

0 comments on commit f5367e9

Please sign in to comment.