Display a progress dialog while deleting a photo
This commit is contained in:
parent
99b150477c
commit
5c53661dd8
3 changed files with 31 additions and 25 deletions
|
@ -11,6 +11,7 @@ import 'package:photos/ui/gallery.dart';
|
|||
import 'package:photos/ui/setup_page.dart';
|
||||
import 'package:photo_manager/photo_manager.dart';
|
||||
import 'package:photos/ui/share_folder_widget.dart';
|
||||
import 'package:photos/utils/dialog_util.dart';
|
||||
import 'package:photos/utils/share_util.dart';
|
||||
|
||||
enum GalleryAppBarType {
|
||||
|
@ -147,15 +148,15 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
CupertinoActionSheetAction(
|
||||
child: Text("Delete on device"),
|
||||
isDestructiveAction: true,
|
||||
onPressed: () async {
|
||||
await _deleteSelected(context, false);
|
||||
onPressed: () {
|
||||
_deleteSelected(context, false);
|
||||
},
|
||||
),
|
||||
CupertinoActionSheetAction(
|
||||
child: Text("Delete everywhere [WiP]"),
|
||||
isDestructiveAction: true,
|
||||
onPressed: () async {
|
||||
await _deleteSelected(context, true);
|
||||
onPressed: () {
|
||||
_deleteSelected(context, true);
|
||||
},
|
||||
)
|
||||
],
|
||||
|
@ -169,7 +170,9 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
showCupertinoModalPopup(context: context, builder: (_) => action);
|
||||
}
|
||||
|
||||
Future _deleteSelected(BuildContext context, bool deleteEverywhere) async {
|
||||
_deleteSelected(BuildContext context, bool deleteEverywhere) async {
|
||||
final dialog = createProgressDialog(context, "Deleting...");
|
||||
await dialog.show();
|
||||
await PhotoManager.editor
|
||||
.deleteWithIds(_selectedFiles.map((p) => p.localId).toList());
|
||||
|
||||
|
@ -181,6 +184,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
Navigator.of(context, rootNavigator: true).pop();
|
||||
FileRepository.instance.reloadFiles();
|
||||
_clearSelectedFiles();
|
||||
await dialog.hide();
|
||||
}
|
||||
|
||||
void _clearSelectedFiles() {
|
||||
|
|
19
lib/utils/dialog_util.dart
Normal file
19
lib/utils/dialog_util.dart
Normal file
|
@ -0,0 +1,19 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
import 'package:progress_dialog/progress_dialog.dart';
|
||||
|
||||
ProgressDialog createProgressDialog(BuildContext context, String message) {
|
||||
final dialog = ProgressDialog(
|
||||
context,
|
||||
type: ProgressDialogType.Normal,
|
||||
isDismissible: false,
|
||||
);
|
||||
dialog.style(
|
||||
message: message,
|
||||
progressWidget: loadWidget,
|
||||
borderRadius: 4.0,
|
||||
elevation: 10.0,
|
||||
insetAnimCurve: Curves.easeInOut,
|
||||
);
|
||||
return dialog;
|
||||
}
|
|
@ -4,11 +4,10 @@ import 'package:esys_flutter_share/esys_flutter_share.dart';
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
import 'package:progress_dialog/progress_dialog.dart';
|
||||
import 'package:photos/utils/dialog_util.dart';
|
||||
|
||||
Future<void> share(BuildContext context, File file) async {
|
||||
final dialog = _getProgressDialog(context);
|
||||
final dialog = createProgressDialog(context, "Preparing...");
|
||||
await dialog.show();
|
||||
final bytes = await file.getBytes();
|
||||
final filename = _getFilename(file.title);
|
||||
|
@ -21,7 +20,7 @@ Future<void> share(BuildContext context, File file) async {
|
|||
}
|
||||
|
||||
Future<void> shareMultiple(BuildContext context, List<File> files) async {
|
||||
final dialog = _getProgressDialog(context);
|
||||
final dialog = createProgressDialog(context, "Preparing...");
|
||||
await dialog.show();
|
||||
final shareContent = Map<String, Uint8List>();
|
||||
for (File file in files) {
|
||||
|
@ -38,19 +37,3 @@ String _getFilename(String name) {
|
|||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
ProgressDialog _getProgressDialog(BuildContext context) {
|
||||
final dialog = ProgressDialog(
|
||||
context,
|
||||
type: ProgressDialogType.Normal,
|
||||
isDismissible: false,
|
||||
);
|
||||
dialog.style(
|
||||
message: "Preparing...",
|
||||
progressWidget: loadWidget,
|
||||
borderRadius: 4.0,
|
||||
elevation: 10.0,
|
||||
insetAnimCurve: Curves.easeInOut,
|
||||
);
|
||||
return dialog;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue