Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Dramatically simplify retrieveLostData
  • Loading branch information
stuartmorgan-g committed Jun 10, 2022
commit 9c95cbda398748c59e6f9497f611cff838a97d69
Original file line number Diff line number Diff line change
Expand Up @@ -144,43 +144,6 @@ class ImagePickerAndroid extends ImagePickerPlatform {
);
}

@override
Future<LostData> retrieveLostData() async {
final Map<String, dynamic>? result =
await _channel.invokeMapMethod<String, dynamic>('retrieve');

if (result == null) {
return LostData.empty();
}

assert(result.containsKey('path') != result.containsKey('errorCode'));

final String? type = result['type'] as String?;
assert(type == kTypeImage || type == kTypeVideo);

RetrieveType? retrieveType;
if (type == kTypeImage) {
retrieveType = RetrieveType.image;
} else if (type == kTypeVideo) {
retrieveType = RetrieveType.video;
}

PlatformException? exception;
if (result.containsKey('errorCode')) {
exception = PlatformException(
code: result['errorCode']! as String,
message: result['errorMessage'] as String?);
}

final String? path = result['path'] as String?;

return LostData(
file: path != null ? PickedFile(path) : null,
exception: exception,
type: retrieveType,
);
}

@override
Future<XFile?> getImage({
required ImageSource source,
Expand Down Expand Up @@ -247,6 +210,21 @@ class ImagePickerAndroid extends ImagePickerPlatform {
return path != null ? XFile(path) : null;
}

@override
Future<LostData> retrieveLostData() async {
final LostDataResponse result = await getLostData();

if (result.isEmpty) {
return LostData.empty();
}

return LostData(
file: result.file != null ? PickedFile(result.file!.path) : null,
exception: result.exception,
type: result.type,
);
}

@override
Future<LostDataResponse> getLostData() async {
List<XFile>? pickedFileList;
Expand Down