diff --git a/.flutter-plugins b/.flutter-plugins deleted file mode 100644 index a935ba1..0000000 --- a/.flutter-plugins +++ /dev/null @@ -1,3 +0,0 @@ -# This is a generated file; do not edit or check into version control. -file_picker=C:\\src\\flutter\\.pub-cache\\hosted\\pub.dartlang.org\\file_picker-5.2.4\\ -flutter_plugin_android_lifecycle=C:\\src\\flutter\\.pub-cache\\hosted\\pub.dartlang.org\\flutter_plugin_android_lifecycle-2.0.7\\ diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies deleted file mode 100644 index 66fe137..0000000 --- a/.flutter-plugins-dependencies +++ /dev/null @@ -1 +0,0 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"file_picker","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\file_picker-5.2.4\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"file_picker","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\file_picker-5.2.4\\\\","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_plugin_android_lifecycle-2.0.7\\\\","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[{"name":"file_picker","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\file_picker-5.2.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]}],"date_created":"2022-12-19 18:52:42.318585","version":"3.3.2"} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 96486fd..35ee281 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ migrate_working_dir/ .dart_tool/ .packages build/ +.flutter-plugins +.flutter-plugins-dependencies diff --git a/CHANGELOG.md b/CHANGELOG.md index 4222baf..821abd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 0.0.7 -- Added support for default images (pre selected images) +- Added support for default images 🖼️ (pre selected images) +- Solved white flash 🔦 problem occurs on add/remove image ## 0.0.6 - 🪲 Fixed some bugs diff --git a/example/pubspec.lock b/example/pubspec.lock index 1376ac0..ea74cd3 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -148,7 +148,7 @@ packages: path: ".." relative: true source: path - version: "0.0.6" + version: "0.0.7" path: dependency: transitive description: diff --git a/lib/src/image_file.dart b/lib/src/image_file.dart index 197d62d..426f201 100644 --- a/lib/src/image_file.dart +++ b/lib/src/image_file.dart @@ -2,6 +2,7 @@ import 'dart:typed_data'; /// Store the image data and other information. class ImageFile { + final String key; final String name; final String extension; final Uint8List? bytes; @@ -13,6 +14,6 @@ class ImageFile { /// returns size of bytes if image has bytes, else 0. int get size => bytes?.length ?? 0; - ImageFile( + ImageFile(this.key, {required this.name, required this.extension, this.bytes, this.path}); } diff --git a/lib/src/multi_image_picker_controller.dart b/lib/src/multi_image_picker_controller.dart index d8ac064..3e44b00 100644 --- a/lib/src/multi_image_picker_controller.dart +++ b/lib/src/multi_image_picker_controller.dart @@ -41,7 +41,7 @@ class MultiImagePickerController with ChangeNotifier { .where((e) => e.extension != null && allowedImageTypes.contains(e.extension?.toLowerCase())) - .map((e) => ImageFile( + .map((e) => ImageFile(UniqueKey().toString(), name: e.name, extension: e.extension!, bytes: e.bytes, diff --git a/lib/src/multi_image_picker_view.dart b/lib/src/multi_image_picker_view.dart index 7c13d02..c6d5905 100644 --- a/lib/src/multi_image_picker_view.dart +++ b/lib/src/multi_image_picker_view.dart @@ -37,30 +37,39 @@ class MultiImagePickerView extends StatefulWidget { final SliverGridDelegate? gridDelegate; - // final images = []; - @override State createState() => _MultiImagePickerViewState(); } class _MultiImagePickerViewState extends State { + late ScrollController scrollController; + final gridViewKey = GlobalKey(); + final selectorKey = GlobalKey(); + @override - Widget build(BuildContext context) { - _pickImages() async { - final result = await widget.controller.pickImages(); - if (!result) return; - if (widget.onChange != null) { - widget.onChange!(widget.controller.images); - } + void initState() { + super.initState(); + scrollController = ScrollController(); + widget.controller.addListener(updateUi); + } + + void _pickImages() async { + final result = await widget.controller.pickImages(); + if (!result) return; + if (widget.onChange != null) { + widget.onChange!(widget.controller.images); } + } - void _deleteImage(ImageFile imageFile) { - widget.controller.removeImage(imageFile); - if (widget.onChange != null) { - widget.onChange!(widget.controller.images); - } + void _deleteImage(ImageFile imageFile) { + widget.controller.removeImage(imageFile); + if (widget.onChange != null) { + widget.onChange!(widget.controller.images); } + } + @override + Widget build(BuildContext context) { if (widget.controller.hasNoImages) { return widget.initialContainerBuilder != null ? widget.initialContainerBuilder!(context, _pickImages) @@ -89,7 +98,7 @@ class _MultiImagePickerViewState extends State { ); } final selector = SizedBox( - key: UniqueKey(), + key: selectorKey, child: widget.addMoreBuilder != null ? widget.addMoreBuilder!(context, _pickImages) : Container( @@ -116,9 +125,6 @@ class _MultiImagePickerViewState extends State { ), ); - final scrollController = ScrollController(); - final gridViewKey = GlobalKey(); - return Padding( padding: widget.padding ?? EdgeInsets.zero, child: ReorderableBuilder( @@ -173,7 +179,7 @@ class _MultiImagePickerViewState extends State { }, children: widget.controller.images .map((e) => SizedBox( - key: UniqueKey(), + key: Key(e.key), child: widget.itemBuilder != null ? widget.itemBuilder!(context, e, _deleteImage) : _ItemView(file: e, onDelete: _deleteImage), @@ -186,12 +192,6 @@ class _MultiImagePickerViewState extends State { ); } - @override - void initState() { - super.initState(); - widget.controller.addListener(updateUi); - } - @override void didUpdateWidget(MultiImagePickerView? oldWidget) { if (oldWidget == null) return; @@ -213,6 +213,7 @@ class _MultiImagePickerViewState extends State { @override void dispose() { widget.controller.removeListener(updateUi); + scrollController.dispose(); super.dispose(); } }