diff --git a/lib/src/image_file.dart b/lib/src/image_file.dart index 3c0787f..197d62d 100644 --- a/lib/src/image_file.dart +++ b/lib/src/image_file.dart @@ -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( diff --git a/lib/src/multi_image_picker_controller.dart b/lib/src/multi_image_picker_controller.dart index eec09a5..7ac4a84 100644 --- a/lib/src/multi_image_picker_controller.dart +++ b/lib/src/multi_image_picker_controller.dart @@ -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 allowedImageTypes; final int maxImages; @@ -15,15 +17,22 @@ class MultiImagePickerController with ChangeNotifier { } final List _images = []; + + /// Returns [Iterable] of [ImageFile] that user has selected. Iterable 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 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 && @@ -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; @@ -56,6 +66,7 @@ class MultiImagePickerController with ChangeNotifier { } } + /// Manually remove image from list. void removeImage(ImageFile imageFile) { _images.remove(imageFile); notifyListeners(); @@ -69,3 +80,4 @@ class MultiImagePickerController with ChangeNotifier { print(_images); } } + diff --git a/lib/src/multi_image_picker_view.dart b/lib/src/multi_image_picker_view.dart index fb4eadd..4bed814 100644 --- a/lib/src/multi_image_picker_view.dart +++ b/lib/src/multi_image_picker_view.dart @@ -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, @@ -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);