[image_picker] Platform interface update cache (#4123)
diff --git a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md
index bd56f0c..97480e0 100644
--- a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md
+++ b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 2.3.0
+
+* Updated `LostDataResponse` to include a `files` property, in case more than one file was recovered.
+
## 2.2.0
* Added new methods that return `XFile` (from `package:cross_file`)
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 bb9e18e..292cb81 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
@@ -227,7 +227,9 @@
@override
Future<LostDataResponse> getLostData() async {
- final Map<String, dynamic>? result =
+ List<XFile>? pickedFileList;
+
+ Map<String, dynamic>? result =
await _channel.invokeMapMethod<String, dynamic>('retrieve');
if (result == null) {
@@ -254,10 +256,20 @@
final String? path = result['path'];
+ final pathList = result['pathList'];
+ if (pathList != null) {
+ pickedFileList = [];
+ // In this case, multiRetrieve is invoked.
+ for (String path in pathList) {
+ pickedFileList.add(XFile(path));
+ }
+ }
+
return LostDataResponse(
file: path != null ? XFile(path) : null,
exception: exception,
type: retrieveType,
+ files: pickedFileList,
);
}
}
diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart b/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart
index 8f9ab99..5c1c8b6 100644
--- a/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart
+++ b/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart
@@ -128,7 +128,8 @@
throw UnimplementedError('pickVideo() has not been implemented.');
}
- /// Retrieve the lost [PickedFile] file when [pickImage] or [pickVideo] failed because the MainActivity is destroyed. (Android only)
+ /// Retrieves any previously picked file, that was lost due to the MainActivity being destroyed.
+ /// In case multiple files were lost, only the last file will be recovered. (Android only).
///
/// Image or video can be lost if the MainActivity is destroyed. And there is no guarantee that the MainActivity is always alive.
/// Call this method to retrieve the lost data and process the data according to your APP's business logic.
@@ -233,8 +234,7 @@
throw UnimplementedError('getVideo() has not been implemented.');
}
- /// Retrieve the lost [XFile] file when [getImage], [getMultiImage] or [getVideo] failed because the MainActivity is
- /// destroyed. (Android only)
+ /// Retrieves any previously picked files, that were lost due to the MainActivity being destroyed. (Android only)
///
/// Image or video can be lost if the MainActivity is destroyed. And there is no guarantee that the MainActivity is
/// always alive. Call this method to retrieve the lost data and process the data according to your APP's business logic.
diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart
index 576ad33..65f5d7e 100644
--- a/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart
+++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart
@@ -14,7 +14,12 @@
class LostDataResponse {
/// Creates an instance with the given [file], [exception], and [type]. Any of
/// the params may be null, but this is never considered to be empty.
- LostDataResponse({this.file, this.exception, this.type});
+ LostDataResponse({
+ this.file,
+ this.exception,
+ this.type,
+ this.files,
+ });
/// Initializes an instance with all member params set to null and considered
/// to be empty.
@@ -22,7 +27,8 @@
: file = null,
exception = null,
type = null,
- _empty = true;
+ _empty = true,
+ files = null;
/// Whether it is an empty response.
///
@@ -50,4 +56,11 @@
final RetrieveType? type;
bool _empty = false;
+
+ /// The list of files that were lost in a previous [getMultiImage] call due to MainActivity being destroyed.
+ ///
+ /// When [files] is populated, [file] will refer to the last item in the [files] list.
+ ///
+ /// Can be null if [exception] exists.
+ final List<XFile>? files;
}
diff --git a/packages/image_picker/image_picker_platform_interface/pubspec.yaml b/packages/image_picker/image_picker_platform_interface/pubspec.yaml
index 0953e76..2168ff0 100644
--- a/packages/image_picker/image_picker_platform_interface/pubspec.yaml
+++ b/packages/image_picker/image_picker_platform_interface/pubspec.yaml
@@ -4,7 +4,7 @@
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
-version: 2.2.0
+version: 2.3.0
environment:
sdk: ">=2.12.0 <3.0.0"
diff --git a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart
index e5321ab..17caa84 100644
--- a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart
+++ b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart
@@ -929,6 +929,22 @@
expect(response.file!.path, '/example/path');
});
+ test('getLostData should successfully retrieve multiple files', () async {
+ picker.channel.setMockMethodCallHandler((MethodCall methodCall) async {
+ return <String, dynamic>{
+ 'type': 'image',
+ 'path': '/example/path1',
+ 'pathList': ['/example/path0', '/example/path1'],
+ };
+ });
+ final LostDataResponse response = await picker.getLostData();
+ expect(response.type, RetrieveType.image);
+ expect(response.file, isNotNull);
+ expect(response.file!.path, '/example/path1');
+ expect(response.files!.first.path, '/example/path0');
+ expect(response.files!.length, 2);
+ });
+
test('getLostData get error response', () async {
picker.channel.setMockMethodCallHandler((MethodCall methodCall) async {
return <String, String>{