From df341db41936c1f1b2a922ead38163874d0817ef Mon Sep 17 00:00:00 2001 From: yusufdag Date: Wed, 30 Jun 2021 15:34:33 +0200 Subject: [PATCH 01/31] Add multiRetrieve method call --- .../java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java index 577675bd433a..bce601912e7e 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java @@ -94,6 +94,7 @@ public void onActivityStopped(Activity activity) { static final String METHOD_CALL_MULTI_IMAGE = "pickMultiImage"; static final String METHOD_CALL_VIDEO = "pickVideo"; private static final String METHOD_CALL_RETRIEVE = "retrieve"; + private static final String METHOD_CALL_MULTI_RETRIEVE = "multiRetrieve"; private static final int CAMERA_DEVICE_FRONT = 1; private static final int CAMERA_DEVICE_REAR = 0; private static final String CHANNEL = "plugins.flutter.io/image_picker"; @@ -320,6 +321,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result rawResult) { } break; case METHOD_CALL_RETRIEVE: + case METHOD_CALL_MULTI_RETRIEVE: delegate.retrieveLostImage(result); break; default: From 2d1a871eeaa277be7421b0846ba479c95ee9a167 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Wed, 30 Jun 2021 15:46:37 +0200 Subject: [PATCH 02/31] Refactor finishWithSuccess to cache list of images I removed the finishWithListSuccess method since it was a temporary solution to save only the last image when multiple images are picked. With the new implementation of caching, finishWithSuccess method save always a list of images to the cache. --- .../imagepicker/ImagePickerDelegate.java | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java index c4a686f5ce13..39b2dc356f98 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java @@ -488,7 +488,7 @@ private void handleChooseImageResult(int resultCode, Intent data) { } // User cancelled choosing a picture. - finishWithSuccess(null); + finishWithSuccess(null, false); } private void handleChooseMultiImageResult(int resultCode, Intent intent) { @@ -506,7 +506,7 @@ private void handleChooseMultiImageResult(int resultCode, Intent intent) { } // User cancelled choosing a picture. - finishWithSuccess(null); + finishWithSuccess(null, false); } private void handleChooseVideoResult(int resultCode, Intent data) { @@ -517,7 +517,7 @@ private void handleChooseVideoResult(int resultCode, Intent data) { } // User cancelled choosing a picture. - finishWithSuccess(null); + finishWithSuccess(null, false); } private void handleCaptureImageResult(int resultCode) { @@ -536,7 +536,7 @@ public void onPathReady(String path) { } // User cancelled taking a picture. - finishWithSuccess(null); + finishWithSuccess(null, false); } private void handleCaptureVideoResult(int resultCode) { @@ -555,7 +555,7 @@ public void onPathReady(String path) { } // User cancelled taking a picture. - finishWithSuccess(null); + finishWithSuccess(null, false); } private void handleMultiImageResult( @@ -572,21 +572,23 @@ private void handleMultiImageResult( } paths.set(i, finalImagePath); } - finishWithListSuccess(paths); + finishWithSuccess(paths, true); } } private void handleImageResult(String path, boolean shouldDeleteOriginalIfScaled) { + ArrayList imageList = new ArrayList(); if (methodCall != null) { String finalImagePath = getResizedImagePath(path); //delete original file if scaled if (finalImagePath != null && !finalImagePath.equals(path) && shouldDeleteOriginalIfScaled) { new File(path).delete(); } - finishWithSuccess(finalImagePath); + imageList.add(finalImagePath); } else { - finishWithSuccess(path); + imageList.add(path); } + finishWithSuccess(imageList, false); } private String getResizedImagePath(String path) { @@ -598,7 +600,9 @@ private String getResizedImagePath(String path) { } private void handleVideoResult(String path) { - finishWithSuccess(path); + ArrayList imageList = new ArrayList(); + imageList.add(path); + finishWithSuccess(imageList, false); } private boolean setPendingMethodCallAndResult( @@ -616,23 +620,17 @@ private boolean setPendingMethodCallAndResult( return true; } - private void finishWithSuccess(String imagePath) { + private void finishWithSuccess(ArrayList imagePath, boolean isMultiImage) { if (pendingResult == null) { cache.saveResult(imagePath, null, null); return; } - pendingResult.success(imagePath); - clearMethodCallAndResult(); - } - private void finishWithListSuccess(ArrayList imagePaths) { - if (pendingResult == null) { - for (String imagePath : imagePaths) { - cache.saveResult(imagePath, null, null); - } - return; + if (isMultiImage) { + pendingResult.success(imagePath); + } else { + pendingResult.success(imagePath.get(0)); } - pendingResult.success(imagePaths); clearMethodCallAndResult(); } From 30a067fea75354272c314c704492b1a694a22754 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Wed, 30 Jun 2021 15:54:26 +0200 Subject: [PATCH 03/31] Refactor retrieveLostImage method Since we are saving always a list of images getCacheMap will return pathList by using the new MAP_KEY_PATH_LIST key. But to avoid breaking change, we are also returning MAP_KEY_PATH with the first element of the list. --- .../imagepicker/ImagePickerDelegate.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java index 39b2dc356f98..9bdaec0d8368 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java @@ -229,17 +229,21 @@ void saveStateBeforeResult() { void retrieveLostImage(MethodChannel.Result result) { Map resultMap = cache.getCacheMap(); - String path = (String) resultMap.get(cache.MAP_KEY_PATH); - if (path != null) { - Double maxWidth = (Double) resultMap.get(cache.MAP_KEY_MAX_WIDTH); - Double maxHeight = (Double) resultMap.get(cache.MAP_KEY_MAX_HEIGHT); - int imageQuality = - resultMap.get(cache.MAP_KEY_IMAGE_QUALITY) == null - ? 100 - : (int) resultMap.get(cache.MAP_KEY_IMAGE_QUALITY); - - String newPath = imageResizer.resizeImageIfNeeded(path, maxWidth, maxHeight, imageQuality); - resultMap.put(cache.MAP_KEY_PATH, newPath); + ArrayList pathList = (ArrayList) resultMap.get(cache.MAP_KEY_PATH_LIST); + ArrayList newPathList = new ArrayList<>(); + if (pathList != null) { + for (String path : pathList) { + Double maxWidth = (Double) resultMap.get(cache.MAP_KEY_MAX_WIDTH); + Double maxHeight = (Double) resultMap.get(cache.MAP_KEY_MAX_HEIGHT); + int imageQuality = + resultMap.get(cache.MAP_KEY_IMAGE_QUALITY) == null + ? 100 + : (int) resultMap.get(cache.MAP_KEY_IMAGE_QUALITY); + + newPathList.add(imageResizer.resizeImageIfNeeded(path, maxWidth, maxHeight, imageQuality)); + } + resultMap.put(cache.MAP_KEY_PATH_LIST, newPathList); + resultMap.put(cache.MAP_KEY_PATH, newPathList.get(0)); } if (resultMap.isEmpty()) { result.success(null); From 01ad85e32b139d5e079c38a0d734303cbbe88130 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Wed, 30 Jun 2021 16:51:38 +0200 Subject: [PATCH 04/31] Add new MAP_KEY_PATH_LIST key --- .../java/io/flutter/plugins/imagepicker/ImagePickerCache.java | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java index 3df0a4108b5c..5ca73b6d7a4a 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java @@ -16,6 +16,7 @@ class ImagePickerCache { static final String MAP_KEY_PATH = "path"; + static final String MAP_KEY_PATH_LIST = "pathList"; static final String MAP_KEY_MAX_WIDTH = "maxWidth"; static final String MAP_KEY_MAX_HEIGHT = "maxHeight"; static final String MAP_KEY_IMAGE_QUALITY = "imageQuality"; From 5a9e99f6da696891bc6c3ed93760fb63a22abd13 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Wed, 30 Jun 2021 16:52:03 +0200 Subject: [PATCH 05/31] Refactor saveTypeWithMethodCallName --- .../java/io/flutter/plugins/imagepicker/ImagePickerCache.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java index 5ca73b6d7a4a..84b78d6a1af5 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java @@ -51,7 +51,8 @@ class ImagePickerCache { } void saveTypeWithMethodCallName(String methodCallName) { - if (methodCallName.equals(ImagePickerPlugin.METHOD_CALL_IMAGE)) { + if (methodCallName.equals(ImagePickerPlugin.METHOD_CALL_IMAGE) + | methodCallName.equals(ImagePickerPlugin.METHOD_CALL_MULTI_IMAGE)) { setType("image"); } else if (methodCallName.equals(ImagePickerPlugin.METHOD_CALL_VIDEO)) { setType("video"); From 364c79daeac3da1c89762bdbf5a635d2827b7807 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Wed, 30 Jun 2021 16:54:24 +0200 Subject: [PATCH 06/31] Update saveResult method I updated saveResult method to use putStringSet method for saving list of images to the cache. --- .../io/flutter/plugins/imagepicker/ImagePickerCache.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java index 84b78d6a1af5..a1185b36744d 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java @@ -10,8 +10,11 @@ import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import io.flutter.plugin.common.MethodCall; +import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; class ImagePickerCache { @@ -101,11 +104,13 @@ String retrievePendingCameraMediaUriPath() { } void saveResult( - @Nullable String path, @Nullable String errorCode, @Nullable String errorMessage) { + @Nullable ArrayList path, @Nullable String errorCode, @Nullable String errorMessage) { + Set imageSet = new HashSet<>(); + imageSet.addAll(path); SharedPreferences.Editor editor = prefs.edit(); if (path != null) { - editor.putString(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY, path); + editor.putStringSet(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY, imageSet); } if (errorCode != null) { editor.putString(SHARED_PREFERENCE_ERROR_CODE_KEY, errorCode); From 757da4caeb49ed0d93f7659d61a07e3edfe70f18 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Wed, 30 Jun 2021 16:55:57 +0200 Subject: [PATCH 07/31] Update the getCacheMap method --- .../io/flutter/plugins/imagepicker/ImagePickerCache.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java index a1185b36744d..e2bb10a02556 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java @@ -128,11 +128,14 @@ void clear() { Map getCacheMap() { Map resultMap = new HashMap<>(); + ArrayList pathList = new ArrayList<>(); boolean hasData = false; if (prefs.contains(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY)) { - final String imagePathValue = prefs.getString(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY, ""); - resultMap.put(MAP_KEY_PATH, imagePathValue); + final Set imagePathList = + prefs.getStringSet(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY, null); + pathList.addAll(imagePathList); + resultMap.put(MAP_KEY_PATH_LIST, pathList); hasData = true; } @@ -166,7 +169,6 @@ Map getCacheMap() { resultMap.put(MAP_KEY_IMAGE_QUALITY, 100); } } - return resultMap; } } From 34186419ecdfe574515ea0af37b9b80a03904d9c Mon Sep 17 00:00:00 2001 From: yusufdag Date: Wed, 30 Jun 2021 17:08:48 +0200 Subject: [PATCH 08/31] Add statement to return null --- .../io/flutter/plugins/imagepicker/ImagePickerDelegate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java index 9bdaec0d8368..906470ba05ec 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java @@ -630,7 +630,7 @@ private void finishWithSuccess(ArrayList imagePath, boolean isMultiImage return; } - if (isMultiImage) { + if (isMultiImage || imagePath == null) { pendingResult.success(imagePath); } else { pendingResult.success(imagePath.get(0)); From 93de29fc96686f5b784a22d23c2ebc1dd3e4917a Mon Sep 17 00:00:00 2001 From: yusufdag Date: Thu, 1 Jul 2021 11:08:09 +0200 Subject: [PATCH 09/31] Update CHANGELOG and version number --- packages/image_picker/image_picker/CHANGELOG.md | 5 +++++ packages/image_picker/image_picker/pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker/CHANGELOG.md b/packages/image_picker/image_picker/CHANGELOG.md index 0e49912b4ed4..4d866304e5e7 100644 --- a/packages/image_picker/image_picker/CHANGELOG.md +++ b/packages/image_picker/image_picker/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.8.2 + +* Update cache system to save list of images and retrieve them when it is needed. On Android, +`getLostData` will return `LostData` object that has new `List` property to get multiple lost images. + ## 0.8.1+3 * Fix image picker causing a crash when the cache directory is deleted. diff --git a/packages/image_picker/image_picker/pubspec.yaml b/packages/image_picker/image_picker/pubspec.yaml index bcda757b4bbf..e515bac461ad 100755 --- a/packages/image_picker/image_picker/pubspec.yaml +++ b/packages/image_picker/image_picker/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for selecting images from the Android and iOS image library, and taking new pictures with the camera. repository: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22 -version: 0.8.1+3 +version: 0.8.2 environment: sdk: ">=2.12.0 <3.0.0" From 9264ad984404fc41ae63a9ce08803c983104ae41 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Thu, 1 Jul 2021 12:57:45 +0200 Subject: [PATCH 10/31] Revert "Refactor finishWithSuccess to cache list of images" This reverts commit 2d1a871eeaa277be7421b0846ba479c95ee9a167. # Conflicts: # packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java --- .../imagepicker/ImagePickerDelegate.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java index 6637e9285231..0166621d4588 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java @@ -493,7 +493,7 @@ private void handleChooseImageResult(int resultCode, Intent data) { } // User cancelled choosing a picture. - finishWithSuccess(null, false); + finishWithSuccess(null); } private void handleChooseMultiImageResult(int resultCode, Intent intent) { @@ -511,7 +511,7 @@ private void handleChooseMultiImageResult(int resultCode, Intent intent) { } // User cancelled choosing a picture. - finishWithSuccess(null, false); + finishWithSuccess(null); } private void handleChooseVideoResult(int resultCode, Intent data) { @@ -522,7 +522,7 @@ private void handleChooseVideoResult(int resultCode, Intent data) { } // User cancelled choosing a picture. - finishWithSuccess(null, false); + finishWithSuccess(null); } private void handleCaptureImageResult(int resultCode) { @@ -541,7 +541,7 @@ public void onPathReady(String path) { } // User cancelled taking a picture. - finishWithSuccess(null, false); + finishWithSuccess(null); } private void handleCaptureVideoResult(int resultCode) { @@ -560,7 +560,7 @@ public void onPathReady(String path) { } // User cancelled taking a picture. - finishWithSuccess(null, false); + finishWithSuccess(null); } private void handleMultiImageResult( @@ -577,23 +577,21 @@ private void handleMultiImageResult( } paths.set(i, finalImagePath); } - finishWithSuccess(paths, true); + finishWithListSuccess(paths); } } private void handleImageResult(String path, boolean shouldDeleteOriginalIfScaled) { - ArrayList imageList = new ArrayList(); if (methodCall != null) { String finalImagePath = getResizedImagePath(path); //delete original file if scaled if (finalImagePath != null && !finalImagePath.equals(path) && shouldDeleteOriginalIfScaled) { new File(path).delete(); } - imageList.add(finalImagePath); + finishWithSuccess(finalImagePath); } else { - imageList.add(path); + finishWithSuccess(path); } - finishWithSuccess(imageList, false); } private String getResizedImagePath(String path) { @@ -605,9 +603,7 @@ private String getResizedImagePath(String path) { } private void handleVideoResult(String path) { - ArrayList imageList = new ArrayList(); - imageList.add(path); - finishWithSuccess(imageList, false); + finishWithSuccess(path); } private boolean setPendingMethodCallAndResult( @@ -625,17 +621,23 @@ private boolean setPendingMethodCallAndResult( return true; } - private void finishWithSuccess(ArrayList imagePath, boolean isMultiImage) { + private void finishWithSuccess(String imagePath) { if (pendingResult == null) { cache.saveResult(imagePath, null, null); return; } + pendingResult.success(imagePath); + clearMethodCallAndResult(); + } - if (isMultiImage || imagePath == null) { - pendingResult.success(imagePath); - } else { - pendingResult.success(imagePath.get(0)); + private void finishWithListSuccess(ArrayList imagePaths) { + if (pendingResult == null) { + for (String imagePath : imagePaths) { + cache.saveResult(imagePath, null, null); + } + return; } + pendingResult.success(imagePaths); clearMethodCallAndResult(); } From e585603b1c2e433c281507f7b4d74b91df02a12f Mon Sep 17 00:00:00 2001 From: yusufdag Date: Thu, 1 Jul 2021 13:00:10 +0200 Subject: [PATCH 11/31] Refactor finishWithSuccess method --- .../plugins/imagepicker/ImagePickerDelegate.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java index 0166621d4588..7ae0aa91e1f9 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java @@ -623,21 +623,21 @@ private boolean setPendingMethodCallAndResult( private void finishWithSuccess(String imagePath) { if (pendingResult == null) { - cache.saveResult(imagePath, null, null); + ArrayList pathList = new ArrayList<>(); + pathList.add(imagePath); + cache.saveResult(pathList, null, null); return; } pendingResult.success(imagePath); clearMethodCallAndResult(); } - private void finishWithListSuccess(ArrayList imagePaths) { + private void finishWithListSuccess(ArrayList imagePath) { if (pendingResult == null) { - for (String imagePath : imagePaths) { - cache.saveResult(imagePath, null, null); - } + cache.saveResult(imagePath, null, null); return; } - pendingResult.success(imagePaths); + pendingResult.success(imagePath); clearMethodCallAndResult(); } From 33fb183be91ff0ab3c8b43287992707dbebbf761 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Thu, 1 Jul 2021 13:01:51 +0200 Subject: [PATCH 12/31] Update dependency version --- packages/image_picker/image_picker/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker/pubspec.yaml b/packages/image_picker/image_picker/pubspec.yaml index e515bac461ad..85baf4e08cd8 100755 --- a/packages/image_picker/image_picker/pubspec.yaml +++ b/packages/image_picker/image_picker/pubspec.yaml @@ -25,7 +25,7 @@ dependencies: sdk: flutter flutter_plugin_android_lifecycle: ^2.0.1 image_picker_for_web: ^2.0.0 - image_picker_platform_interface: ^2.1.0 + image_picker_platform_interface: ^2.2.0 dev_dependencies: flutter_test: From ec4079ef86794d873492fa30f9bf0ccac24e5a67 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 16 Jul 2021 15:46:51 +0200 Subject: [PATCH 13/31] Update version and CHANGELOG --- packages/image_picker/image_picker/CHANGELOG.md | 3 ++- packages/image_picker/image_picker/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/image_picker/image_picker/CHANGELOG.md b/packages/image_picker/image_picker/CHANGELOG.md index 8838e95e71fe..44262e3661ea 100644 --- a/packages/image_picker/image_picker/CHANGELOG.md +++ b/packages/image_picker/image_picker/CHANGELOG.md @@ -1,7 +1,8 @@ ## 0.8.3 * Update cache system to save list of images and retrieve them when it is needed. On Android, -`getLostData` will return `LostData` object that has new `List` property to get multiple lost images. +`List files` property added to `LostData` and `List files` property added to +`LostDataResponse` in the case multiple picked images were recovered. ## 0.8.2 diff --git a/packages/image_picker/image_picker/pubspec.yaml b/packages/image_picker/image_picker/pubspec.yaml index e5ecfeb22232..f56250f53715 100755 --- a/packages/image_picker/image_picker/pubspec.yaml +++ b/packages/image_picker/image_picker/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for selecting images from the Android and iOS image library, and taking new pictures with the camera. repository: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22 -version: 0.8.2 +version: 0.8.3 environment: sdk: ">=2.12.0 <3.0.0" From a67535251849e72149adbdefddf5fe461fe8a420 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 16 Jul 2021 15:52:35 +0200 Subject: [PATCH 14/31] Add unit tests --- .../test/image_picker_deprecated_test.dart | 35 +++++++++++++++++++ .../image_picker/test/image_picker_test.dart | 35 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/packages/image_picker/image_picker/test/image_picker_deprecated_test.dart b/packages/image_picker/image_picker/test/image_picker_deprecated_test.dart index f295e3d02f66..b60e09b89548 100644 --- a/packages/image_picker/image_picker/test/image_picker_deprecated_test.dart +++ b/packages/image_picker/image_picker/test/image_picker_deprecated_test.dart @@ -320,6 +320,41 @@ void main() { expect(response.file!.path, '/example/path'); }); + test('retrieveLostData get success response with pathList', () async { + channel.setMockMethodCallHandler((MethodCall methodCall) async { + return { + 'type': 'image', + 'path': '/example/path', + 'pathList': ['/example/path'], + }; + }); + + final LostData response = await picker.getLostData(); + expect(response.type, RetrieveType.image); + expect(response.file, isNotNull); + expect(response.file!.path, '/example/path'); + expect(response.files!.first.path, '/example/path'); + }); + + test('retrieveLostData is failed for multiRetrieve method call', + () async { + channel.setMockMethodCallHandler((MethodCall methodCall) async { + switch (methodCall.method) { + case 'multiRetrieve': + throw MissingPluginException(); + case 'retrieve': + return { + 'type': 'image', + 'path': '/example/path', + 'pathList': null, + }; + } + }); + + final LostData response = await picker.getLostData(); + expect(response.files, null); + }); + test('retrieveLostData get error response', () async { channel.setMockMethodCallHandler((MethodCall methodCall) async { return { diff --git a/packages/image_picker/image_picker/test/image_picker_test.dart b/packages/image_picker/image_picker/test/image_picker_test.dart index 960dfe6917ea..518d1773350f 100644 --- a/packages/image_picker/image_picker/test/image_picker_test.dart +++ b/packages/image_picker/image_picker/test/image_picker_test.dart @@ -315,6 +315,41 @@ void main() { expect(response.file!.path, '/example/path'); }); + test('retrieveLostData get success response with pathList', () async { + channel.setMockMethodCallHandler((MethodCall methodCall) async { + return { + 'type': 'image', + 'path': '/example/path', + 'pathList': ['/example/path'], + }; + }); + + final LostDataResponse response = await picker.retrieveLostData(); + expect(response.type, RetrieveType.image); + expect(response.file, isNotNull); + expect(response.file!.path, '/example/path'); + expect(response.files!.first.path, '/example/path'); + }); + + test('retrieveLostData is failed for multiRetrieve method call', + () async { + channel.setMockMethodCallHandler((MethodCall methodCall) async { + switch (methodCall.method) { + case 'multiRetrieve': + throw MissingPluginException(); + case 'retrieve': + return { + 'type': 'image', + 'path': '/example/path', + 'pathList': null, + }; + } + }); + + final LostDataResponse response = await picker.retrieveLostData(); + expect(response.files, null); + }); + test('retrieveLostData get error response', () async { channel.setMockMethodCallHandler((MethodCall methodCall) async { return { From 91fd73d60c15103e6fa38864d6beb35a13533004 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 16 Jul 2021 16:12:03 +0200 Subject: [PATCH 15/31] Update CHANGELOG --- packages/image_picker/image_picker/CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/image_picker/image_picker/CHANGELOG.md b/packages/image_picker/image_picker/CHANGELOG.md index 44262e3661ea..03214c650b09 100644 --- a/packages/image_picker/image_picker/CHANGELOG.md +++ b/packages/image_picker/image_picker/CHANGELOG.md @@ -1,8 +1,6 @@ ## 0.8.3 -* Update cache system to save list of images and retrieve them when it is needed. On Android, -`List files` property added to `LostData` and `List files` property added to -`LostDataResponse` in the case multiple picked images were recovered. +* Update `ImagePickerCache` to save list of images and recover them when it is needed. ## 0.8.2 From 56c29b02978f025656746a55e142a4a7e07f7988 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Sat, 17 Jul 2021 12:12:25 +0200 Subject: [PATCH 16/31] Update dependency version --- packages/image_picker/image_picker/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker/pubspec.yaml b/packages/image_picker/image_picker/pubspec.yaml index f56250f53715..291710720b46 100755 --- a/packages/image_picker/image_picker/pubspec.yaml +++ b/packages/image_picker/image_picker/pubspec.yaml @@ -25,7 +25,7 @@ dependencies: sdk: flutter flutter_plugin_android_lifecycle: ^2.0.1 image_picker_for_web: ^2.1.0 - image_picker_platform_interface: ^2.2.0 + image_picker_platform_interface: ^2.2.1 dev_dependencies: flutter_test: From 156d8459d75e972fd0b08b5ae07814f2865c622d Mon Sep 17 00:00:00 2001 From: yusufdag Date: Wed, 21 Jul 2021 16:16:44 +0200 Subject: [PATCH 17/31] Remove unused method call --- .../java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java index bce601912e7e..577675bd433a 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java @@ -94,7 +94,6 @@ public void onActivityStopped(Activity activity) { static final String METHOD_CALL_MULTI_IMAGE = "pickMultiImage"; static final String METHOD_CALL_VIDEO = "pickVideo"; private static final String METHOD_CALL_RETRIEVE = "retrieve"; - private static final String METHOD_CALL_MULTI_RETRIEVE = "multiRetrieve"; private static final int CAMERA_DEVICE_FRONT = 1; private static final int CAMERA_DEVICE_REAR = 0; private static final String CHANNEL = "plugins.flutter.io/image_picker"; @@ -321,7 +320,6 @@ public void onMethodCall(MethodCall call, MethodChannel.Result rawResult) { } break; case METHOD_CALL_RETRIEVE: - case METHOD_CALL_MULTI_RETRIEVE: delegate.retrieveLostImage(result); break; default: From c38ad2b4c3a10a4bbebbc0a8b9d0242665729e35 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 20 Aug 2021 09:35:32 +0200 Subject: [PATCH 18/31] Remove unit tests from deprecated LostData --- .../test/image_picker_deprecated_test.dart | 35 ------------------- 1 file changed, 35 deletions(-) diff --git a/packages/image_picker/image_picker/test/image_picker_deprecated_test.dart b/packages/image_picker/image_picker/test/image_picker_deprecated_test.dart index b60e09b89548..f295e3d02f66 100644 --- a/packages/image_picker/image_picker/test/image_picker_deprecated_test.dart +++ b/packages/image_picker/image_picker/test/image_picker_deprecated_test.dart @@ -320,41 +320,6 @@ void main() { expect(response.file!.path, '/example/path'); }); - test('retrieveLostData get success response with pathList', () async { - channel.setMockMethodCallHandler((MethodCall methodCall) async { - return { - 'type': 'image', - 'path': '/example/path', - 'pathList': ['/example/path'], - }; - }); - - final LostData response = await picker.getLostData(); - expect(response.type, RetrieveType.image); - expect(response.file, isNotNull); - expect(response.file!.path, '/example/path'); - expect(response.files!.first.path, '/example/path'); - }); - - test('retrieveLostData is failed for multiRetrieve method call', - () async { - channel.setMockMethodCallHandler((MethodCall methodCall) async { - switch (methodCall.method) { - case 'multiRetrieve': - throw MissingPluginException(); - case 'retrieve': - return { - 'type': 'image', - 'path': '/example/path', - 'pathList': null, - }; - } - }); - - final LostData response = await picker.getLostData(); - expect(response.files, null); - }); - test('retrieveLostData get error response', () async { channel.setMockMethodCallHandler((MethodCall methodCall) async { return { From 27f87ca2854744cd77107f8fcdbcd3d3e3a619da Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 20 Aug 2021 09:37:06 +0200 Subject: [PATCH 19/31] Remove redundant unit test This test is removed because `multiRetrieved` method call was removed. --- .../image_picker/test/image_picker_test.dart | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/packages/image_picker/image_picker/test/image_picker_test.dart b/packages/image_picker/image_picker/test/image_picker_test.dart index 518d1773350f..7494fc0466cf 100644 --- a/packages/image_picker/image_picker/test/image_picker_test.dart +++ b/packages/image_picker/image_picker/test/image_picker_test.dart @@ -331,25 +331,6 @@ void main() { expect(response.files!.first.path, '/example/path'); }); - test('retrieveLostData is failed for multiRetrieve method call', - () async { - channel.setMockMethodCallHandler((MethodCall methodCall) async { - switch (methodCall.method) { - case 'multiRetrieve': - throw MissingPluginException(); - case 'retrieve': - return { - 'type': 'image', - 'path': '/example/path', - 'pathList': null, - }; - } - }); - - final LostDataResponse response = await picker.retrieveLostData(); - expect(response.files, null); - }); - test('retrieveLostData get error response', () async { channel.setMockMethodCallHandler((MethodCall methodCall) async { return { From c56752586e63530e30ad7bf22784e79381d04ca2 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 20 Aug 2021 10:31:00 +0200 Subject: [PATCH 20/31] Refactor to assign the last item to path to avoid breaking change --- .../io/flutter/plugins/imagepicker/ImagePickerDelegate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java index 7ae0aa91e1f9..ea3e4c42d687 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java @@ -243,7 +243,7 @@ void retrieveLostImage(MethodChannel.Result result) { newPathList.add(imageResizer.resizeImageIfNeeded(path, maxWidth, maxHeight, imageQuality)); } resultMap.put(cache.MAP_KEY_PATH_LIST, newPathList); - resultMap.put(cache.MAP_KEY_PATH, newPathList.get(0)); + resultMap.put(cache.MAP_KEY_PATH, newPathList.get(newPathList.size() - 1)); } if (resultMap.isEmpty()) { result.success(null); From 0454d807860924f88213bbe6b494e4043a44e739 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 20 Aug 2021 10:45:08 +0200 Subject: [PATCH 21/31] Refactor retrieveLostData multiple files unit test --- .../image_picker/test/image_picker_test.dart | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/image_picker/image_picker/test/image_picker_test.dart b/packages/image_picker/image_picker/test/image_picker_test.dart index 7494fc0466cf..2600ee300636 100644 --- a/packages/image_picker/image_picker/test/image_picker_test.dart +++ b/packages/image_picker/image_picker/test/image_picker_test.dart @@ -315,20 +315,22 @@ void main() { expect(response.file!.path, '/example/path'); }); - test('retrieveLostData get success response with pathList', () async { + test('retrieveLostData should successfully retrieve multiple files', + () async { channel.setMockMethodCallHandler((MethodCall methodCall) async { return { 'type': 'image', - 'path': '/example/path', - 'pathList': ['/example/path'], + 'path': '/example/path1', + 'pathList': ['/example/path0', '/example/path1'], }; }); final LostDataResponse response = await picker.retrieveLostData(); expect(response.type, RetrieveType.image); expect(response.file, isNotNull); - expect(response.file!.path, '/example/path'); - expect(response.files!.first.path, '/example/path'); + expect(response.file!.path, '/example/path1'); + expect(response.files!.first.path, '/example/path0'); + expect(response.files!.length(), 2); }); test('retrieveLostData get error response', () async { From db5d48e4187e543e8421a20e71c6794e1b75c635 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 20 Aug 2021 12:07:16 +0200 Subject: [PATCH 22/31] Update the dependency version --- packages/image_picker/image_picker/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker/pubspec.yaml b/packages/image_picker/image_picker/pubspec.yaml index 291710720b46..7264ea64162b 100755 --- a/packages/image_picker/image_picker/pubspec.yaml +++ b/packages/image_picker/image_picker/pubspec.yaml @@ -25,7 +25,7 @@ dependencies: sdk: flutter flutter_plugin_android_lifecycle: ^2.0.1 image_picker_for_web: ^2.1.0 - image_picker_platform_interface: ^2.2.1 + image_picker_platform_interface: ^2.3.0 dev_dependencies: flutter_test: From e8d71e9c7f16f7cd1b6b3629def6717e9bb2c204 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Thu, 26 Aug 2021 10:47:39 +0200 Subject: [PATCH 23/31] Fix the length call --- packages/image_picker/image_picker/test/image_picker_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker/test/image_picker_test.dart b/packages/image_picker/image_picker/test/image_picker_test.dart index 2600ee300636..10bc64082aca 100644 --- a/packages/image_picker/image_picker/test/image_picker_test.dart +++ b/packages/image_picker/image_picker/test/image_picker_test.dart @@ -330,7 +330,7 @@ void main() { expect(response.file, isNotNull); expect(response.file!.path, '/example/path1'); expect(response.files!.first.path, '/example/path0'); - expect(response.files!.length(), 2); + expect(response.files!.length, 2); }); test('retrieveLostData get error response', () async { From 933931b3d85a637a86bbd7355736a4aa95189508 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Thu, 26 Aug 2021 13:53:30 +0200 Subject: [PATCH 24/31] Update the CHANGELOG --- packages/image_picker/image_picker/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker/CHANGELOG.md b/packages/image_picker/image_picker/CHANGELOG.md index d0067db097bd..1a4c84b3f2b3 100644 --- a/packages/image_picker/image_picker/CHANGELOG.md +++ b/packages/image_picker/image_picker/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.8.4 -* Update `ImagePickerCache` to save list of images, in case more than one file was recovered. +* Update `ImagePickerCache` to save and to recover multiple files. ## 0.8.3+3 From c08c461076a4794a86140831f2446c86b66d5dcf Mon Sep 17 00:00:00 2001 From: yusufdag Date: Thu, 26 Aug 2021 13:54:43 +0200 Subject: [PATCH 25/31] Update CHANGELOG --- packages/image_picker/image_picker/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker/CHANGELOG.md b/packages/image_picker/image_picker/CHANGELOG.md index 1a4c84b3f2b3..5dc260993773 100644 --- a/packages/image_picker/image_picker/CHANGELOG.md +++ b/packages/image_picker/image_picker/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.8.4 -* Update `ImagePickerCache` to save and to recover multiple files. +* Update `ImagePickerCache` to cache multiple files. ## 0.8.3+3 From a43ffebdcdd8283cd8f392797aba1ed767146481 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 27 Aug 2021 08:46:45 +0200 Subject: [PATCH 26/31] Add null check --- .../io/flutter/plugins/imagepicker/ImagePickerCache.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java index e2bb10a02556..983dbabf66c3 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java @@ -134,9 +134,11 @@ Map getCacheMap() { if (prefs.contains(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY)) { final Set imagePathList = prefs.getStringSet(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY, null); - pathList.addAll(imagePathList); - resultMap.put(MAP_KEY_PATH_LIST, pathList); - hasData = true; + if (imagePathList != null) { + pathList.addAll(imagePathList); + resultMap.put(MAP_KEY_PATH_LIST, pathList); + hasData = true; + } } if (prefs.contains(SHARED_PREFERENCE_ERROR_CODE_KEY)) { From ced68ec07dde2686abd69186f24df1e0aaf2286d Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 27 Aug 2021 08:47:07 +0200 Subject: [PATCH 27/31] Add unit test --- .../imagepicker/ImagePickerDelegateTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/image_picker/image_picker/android/src/test/java/io/flutter/plugins/imagepicker/ImagePickerDelegateTest.java b/packages/image_picker/image_picker/android/src/test/java/io/flutter/plugins/imagepicker/ImagePickerDelegateTest.java index ebd58d05fee4..d2ee7b0b7d61 100644 --- a/packages/image_picker/image_picker/android/src/test/java/io/flutter/plugins/imagepicker/ImagePickerDelegateTest.java +++ b/packages/image_picker/image_picker/android/src/test/java/io/flutter/plugins/imagepicker/ImagePickerDelegateTest.java @@ -5,10 +5,12 @@ package io.flutter.plugins.imagepicker; import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -26,9 +28,13 @@ import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; @@ -368,6 +374,34 @@ public void onActivityResult_WhenImageTakenWithCamera_AndNoResizeNeeded_Finishes verifyNoMoreInteractions(mockResult); } + @Test + public void + retrieveLostImage_ShouldBeAbleToReturnLastItemFromResultMapWhenSingleFileIsRecovered() { + Map resultMap = new HashMap<>(); + ArrayList pathList = new ArrayList<>(); + pathList.add("/example/first_item"); + pathList.add("/example/last_item"); + resultMap.put("pathList", pathList); + + when(mockImageResizer.resizeImageIfNeeded(pathList.get(0), null, null, 100)) + .thenReturn(pathList.get(0)); + when(mockImageResizer.resizeImageIfNeeded(pathList.get(1), null, null, 100)) + .thenReturn(pathList.get(1)); + when(cache.getCacheMap()).thenReturn(resultMap); + + MethodChannel.Result mockResult = mock(MethodChannel.Result.class); + + ImagePickerDelegate mockDelegate = createDelegate(); + + ArgumentCaptor> valueCapture = ArgumentCaptor.forClass(Map.class); + + doNothing().when(mockResult).success(valueCapture.capture()); + + mockDelegate.retrieveLostImage(mockResult); + + assertEquals("/example/last_item", valueCapture.getValue().get("path")); + } + private ImagePickerDelegate createDelegate() { return new ImagePickerDelegate( mockActivity, From 0325f33b425731a6e51050af929fa0d6e674fa92 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 27 Aug 2021 12:24:35 +0200 Subject: [PATCH 28/31] Update the example app --- packages/image_picker/image_picker/example/lib/main.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/image_picker/image_picker/example/lib/main.dart b/packages/image_picker/image_picker/example/lib/main.dart index 2d5fd9aee4a7..0f5ba76db6df 100755 --- a/packages/image_picker/image_picker/example/lib/main.dart +++ b/packages/image_picker/image_picker/example/lib/main.dart @@ -226,6 +226,7 @@ class _MyHomePageState extends State { isVideo = false; setState(() { _imageFile = response.file; + _imageFileList = response.files; }); } } else { From 29d9e0e96baf290651859d66ed292e2375679e7b Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 27 Aug 2021 12:30:10 +0200 Subject: [PATCH 29/31] Remove redundant comment --- .../lib/src/method_channel/method_channel_image_picker.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart index 292cb814ddeb..b02284e957fa 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart @@ -259,7 +259,6 @@ class MethodChannelImagePicker extends ImagePickerPlatform { final pathList = result['pathList']; if (pathList != null) { pickedFileList = []; - // In this case, multiRetrieve is invoked. for (String path in pathList) { pickedFileList.add(XFile(path)); } From 4ad0263c0244622f66cefb9c9d957148cbdd59b7 Mon Sep 17 00:00:00 2001 From: yusufdag Date: Fri, 27 Aug 2021 12:30:28 +0200 Subject: [PATCH 30/31] Refactor handleMultiImageResult --- .../io/flutter/plugins/imagepicker/ImagePickerDelegate.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java index cd5a1089ed5a..eef1a1006ef1 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java @@ -562,6 +562,7 @@ public void onPathReady(String path) { private void handleMultiImageResult( ArrayList paths, boolean shouldDeleteOriginalIfScaled) { if (methodCall != null) { + ArrayList finalPath = new ArrayList<>(); for (int i = 0; i < paths.size(); i++) { String finalImagePath = getResizedImagePath(paths.get(i)); @@ -571,8 +572,10 @@ private void handleMultiImageResult( && shouldDeleteOriginalIfScaled) { new File(paths.get(i)).delete(); } - paths.set(i, finalImagePath); + finalPath.add(i, finalImagePath); } + finishWithListSuccess(finalPath); + } else { finishWithListSuccess(paths); } } From 076451415e4ed8790d0e5c798da13537de5fa21d Mon Sep 17 00:00:00 2001 From: BeMacized Date: Mon, 30 Aug 2021 11:43:39 +0200 Subject: [PATCH 31/31] Variable rename --- .../io/flutter/plugins/imagepicker/ImagePickerDelegate.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java index eef1a1006ef1..a60c1f173041 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java @@ -631,12 +631,12 @@ private void finishWithSuccess(String imagePath) { clearMethodCallAndResult(); } - private void finishWithListSuccess(ArrayList imagePath) { + private void finishWithListSuccess(ArrayList imagePaths) { if (pendingResult == null) { - cache.saveResult(imagePath, null, null); + cache.saveResult(imagePaths, null, null); return; } - pendingResult.success(imagePath); + pendingResult.success(imagePaths); clearMethodCallAndResult(); }