Skip to content

Commit

Permalink
🔥 Remove duplicate future requests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Jan 17, 2022
1 parent dbbbde2 commit e0c3bc5
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions lib/src/widgets/camera_picker_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,29 +219,25 @@ class _CameraPickerViewerState extends State<CameraPickerViewer> {
);
return;
}
Future<AssetEntity?> saveFuture;

switch (pickerType) {
case CameraPickerViewType.image:
final Uint8List data = await previewFile.readAsBytes();
saveFuture = PhotoManager.editor.saveImage(
data,
title: path.basename(previewFile.path),
);
break;
case CameraPickerViewType.video:
saveFuture = PhotoManager.editor.saveVideo(
previewFile,
title: path.basename(previewFile.path),
);
break;
}

AssetEntity? entity;
try {
final PermissionState _ps = await PhotoManager.requestPermissionExtend();
if (_ps == PermissionState.authorized || _ps == PermissionState.limited) {
entity = await saveFuture;
switch (pickerType) {
case CameraPickerViewType.image:
final Uint8List data = await previewFile.readAsBytes();
entity = await PhotoManager.editor.saveImage(
data,
title: path.basename(previewFile.path),
);
break;
case CameraPickerViewType.video:
entity = await PhotoManager.editor.saveVideo(
previewFile,
title: path.basename(previewFile.path),
);
break;
}
if (shouldDeletePreviewFile && previewFile.existsSync()) {
previewFile.delete();
}
Expand Down

0 comments on commit e0c3bc5

Please sign in to comment.