Modified uses of ActionSheets to work with ButtonWidget
This commit is contained in:
parent
ee3d152083
commit
dd49b7913d
10 changed files with 69 additions and 51 deletions
|
@ -57,7 +57,8 @@ extension CollectionFileActions on CollectionActions {
|
||||||
: "Selected items will be removed from this album",
|
: "Selected items will be removed from this album",
|
||||||
actionSheetType: ActionSheetType.defaultActionSheet,
|
actionSheetType: ActionSheetType.defaultActionSheet,
|
||||||
);
|
);
|
||||||
if (actionResult != null && actionResult == ButtonAction.error) {
|
if (actionResult?.action != null &&
|
||||||
|
actionResult!.action == ButtonAction.error) {
|
||||||
showGenericErrorDialog(context: bContext);
|
showGenericErrorDialog(context: bContext);
|
||||||
} else {
|
} else {
|
||||||
selectedFiles.clearAll();
|
selectedFiles.clearAll();
|
||||||
|
|
|
@ -54,7 +54,7 @@ class CollectionActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> disableUrl(BuildContext context, Collection collection) async {
|
Future<bool> disableUrl(BuildContext context, Collection collection) async {
|
||||||
final ButtonAction? result = await showActionSheet(
|
final actionResult = await showActionSheet(
|
||||||
context: context,
|
context: context,
|
||||||
buttons: [
|
buttons: [
|
||||||
ButtonWidget(
|
ButtonWidget(
|
||||||
|
@ -80,11 +80,11 @@ class CollectionActions {
|
||||||
body:
|
body:
|
||||||
'This will remove the public link for accessing "${collection.name}".',
|
'This will remove the public link for accessing "${collection.name}".',
|
||||||
);
|
);
|
||||||
if (result != null) {
|
if (actionResult?.action != null) {
|
||||||
if (result == ButtonAction.error) {
|
if (actionResult!.action == ButtonAction.error) {
|
||||||
showGenericErrorDialog(context: context);
|
showGenericErrorDialog(context: context);
|
||||||
}
|
}
|
||||||
return result == ButtonAction.first;
|
return actionResult.action == ButtonAction.first;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ class CollectionActions {
|
||||||
Collection collection,
|
Collection collection,
|
||||||
User user,
|
User user,
|
||||||
) async {
|
) async {
|
||||||
final ButtonAction? result = await showActionSheet(
|
final actionResult = await showActionSheet(
|
||||||
context: context,
|
context: context,
|
||||||
buttons: [
|
buttons: [
|
||||||
ButtonWidget(
|
ButtonWidget(
|
||||||
|
@ -168,11 +168,11 @@ class CollectionActions {
|
||||||
body: '${user.email} will be removed from this shared album\n\nAny '
|
body: '${user.email} will be removed from this shared album\n\nAny '
|
||||||
'photos added by them will also be removed from the album',
|
'photos added by them will also be removed from the album',
|
||||||
);
|
);
|
||||||
if (result != null) {
|
if (actionResult?.action != null) {
|
||||||
if (result == ButtonAction.error) {
|
if (actionResult!.action == ButtonAction.error) {
|
||||||
showGenericErrorDialog(context: context);
|
showGenericErrorDialog(context: context);
|
||||||
}
|
}
|
||||||
return result == ButtonAction.first;
|
return actionResult.action == ButtonAction.first;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -346,13 +346,14 @@ class CollectionActions {
|
||||||
),
|
),
|
||||||
actionSheetType: ActionSheetType.defaultActionSheet,
|
actionSheetType: ActionSheetType.defaultActionSheet,
|
||||||
);
|
);
|
||||||
if (actionResult != null && actionResult == ButtonAction.error) {
|
if (actionResult?.action != null &&
|
||||||
|
actionResult!.action == ButtonAction.error) {
|
||||||
showGenericErrorDialog(context: bContext);
|
showGenericErrorDialog(context: bContext);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (actionResult != null &&
|
if ((actionResult?.action != null) &&
|
||||||
(actionResult == ButtonAction.first ||
|
(actionResult!.action == ButtonAction.first ||
|
||||||
actionResult == ButtonAction.second)) {
|
actionResult.action == ButtonAction.second)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -364,7 +365,7 @@ class CollectionActions {
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
Collection collection,
|
Collection collection,
|
||||||
) async {
|
) async {
|
||||||
final ButtonAction? result = await showChoiceActionSheet(
|
final actionResult = await showChoiceActionSheet(
|
||||||
context,
|
context,
|
||||||
isCritical: true,
|
isCritical: true,
|
||||||
title: "Delete shared album?",
|
title: "Delete shared album?",
|
||||||
|
@ -372,7 +373,8 @@ class CollectionActions {
|
||||||
body: "The album will be deleted for everyone\n\nYou will lose access to "
|
body: "The album will be deleted for everyone\n\nYou will lose access to "
|
||||||
"shared photos in this album that are owned by others",
|
"shared photos in this album that are owned by others",
|
||||||
);
|
);
|
||||||
return result != null && result == ButtonAction.first;
|
return actionResult?.action != null &&
|
||||||
|
actionResult!.action == ButtonAction.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ui';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
|
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
|
||||||
import 'package:photos/core/constants.dart';
|
import 'package:photos/core/constants.dart';
|
||||||
|
import "package:photos/models/search/button_result.dart";
|
||||||
import 'package:photos/theme/colors.dart';
|
import 'package:photos/theme/colors.dart';
|
||||||
import 'package:photos/theme/effects.dart';
|
import 'package:photos/theme/effects.dart';
|
||||||
import 'package:photos/theme/ente_theme.dart';
|
import 'package:photos/theme/ente_theme.dart';
|
||||||
|
@ -15,7 +16,7 @@ enum ActionSheetType {
|
||||||
}
|
}
|
||||||
|
|
||||||
///Returns null if dismissed
|
///Returns null if dismissed
|
||||||
Future<ButtonAction?> showActionSheet({
|
Future<ButtonResult?> showActionSheet({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required List<ButtonWidget> buttons,
|
required List<ButtonWidget> buttons,
|
||||||
ActionSheetType actionSheetType = ActionSheetType.defaultActionSheet,
|
ActionSheetType actionSheetType = ActionSheetType.defaultActionSheet,
|
||||||
|
|
|
@ -108,7 +108,7 @@ class _ManageIndividualParticipantState
|
||||||
onTap: widget.user.isViewer
|
onTap: widget.user.isViewer
|
||||||
? null
|
? null
|
||||||
: () async {
|
: () async {
|
||||||
final ButtonAction? result = await showChoiceActionSheet(
|
final actionResult = await showChoiceActionSheet(
|
||||||
context,
|
context,
|
||||||
title: "Change permissions?",
|
title: "Change permissions?",
|
||||||
firstButtonLabel: "Yes, convert to viewer",
|
firstButtonLabel: "Yes, convert to viewer",
|
||||||
|
@ -116,8 +116,8 @@ class _ManageIndividualParticipantState
|
||||||
'${widget.user.email} will not be able to add more photos to this album\n\nThey will still be able to remove existing photos added by them',
|
'${widget.user.email} will not be able to add more photos to this album\n\nThey will still be able to remove existing photos added by them',
|
||||||
isCritical: true,
|
isCritical: true,
|
||||||
);
|
);
|
||||||
if (result != null) {
|
if (actionResult?.action != null) {
|
||||||
if (result == ButtonAction.first) {
|
if (actionResult!.action == ButtonAction.first) {
|
||||||
try {
|
try {
|
||||||
isConvertToViewSuccess =
|
isConvertToViewSuccess =
|
||||||
await collectionActions.addEmailToCollection(
|
await collectionActions.addEmailToCollection(
|
||||||
|
|
|
@ -524,7 +524,8 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
|
||||||
body: "Do you want to discard the edits you have made?",
|
body: "Do you want to discard the edits you have made?",
|
||||||
actionSheetType: ActionSheetType.defaultActionSheet,
|
actionSheetType: ActionSheetType.defaultActionSheet,
|
||||||
);
|
);
|
||||||
if (actionResult != null && actionResult == ButtonAction.first) {
|
if (actionResult?.action != null &&
|
||||||
|
actionResult!.action == ButtonAction.first) {
|
||||||
replacePage(context, DetailPage(widget.detailPageConfig));
|
replacePage(context, DetailPage(widget.detailPageConfig));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -428,15 +428,18 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
|
||||||
body: "You can manage your links in the share tab.",
|
body: "You can manage your links in the share tab.",
|
||||||
actionSheetType: ActionSheetType.defaultActionSheet,
|
actionSheetType: ActionSheetType.defaultActionSheet,
|
||||||
);
|
);
|
||||||
if (actionResult != null && actionResult == ButtonAction.first) {
|
if (actionResult?.action != null) {
|
||||||
await _copyLink();
|
if (actionResult!.action == ButtonAction.first) {
|
||||||
}
|
await _copyLink();
|
||||||
if (actionResult != null && actionResult == ButtonAction.second) {
|
}
|
||||||
routeToPage(
|
if (actionResult.action == ButtonAction.second) {
|
||||||
context,
|
routeToPage(
|
||||||
ManageSharedLinkWidget(collection: _cachedCollectionForSharedLink),
|
context,
|
||||||
);
|
ManageSharedLinkWidget(collection: _cachedCollectionForSharedLink),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() => {});
|
setState(() => {});
|
||||||
}
|
}
|
||||||
|
|
|
@ -431,14 +431,15 @@ class FadingAppBarState extends State<FadingAppBar> {
|
||||||
isInAlert: true,
|
isInAlert: true,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final ButtonAction? result = await showActionSheet(
|
final actionResult = await showActionSheet(
|
||||||
context: context,
|
context: context,
|
||||||
buttons: buttons,
|
buttons: buttons,
|
||||||
actionSheetType: ActionSheetType.defaultActionSheet,
|
actionSheetType: ActionSheetType.defaultActionSheet,
|
||||||
body: body,
|
body: body,
|
||||||
bodyHighlight: bodyHighlight,
|
bodyHighlight: bodyHighlight,
|
||||||
);
|
);
|
||||||
if (result != null && result == ButtonAction.error) {
|
if (actionResult?.action != null &&
|
||||||
|
actionResult!.action == ButtonAction.error) {
|
||||||
showGenericErrorDialog(context: context);
|
showGenericErrorDialog(context: context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> _leaveAlbum(BuildContext context) async {
|
Future<dynamic> _leaveAlbum(BuildContext context) async {
|
||||||
final ButtonAction? result = await showActionSheet(
|
final actionResult = await showActionSheet(
|
||||||
context: context,
|
context: context,
|
||||||
buttons: [
|
buttons: [
|
||||||
ButtonWidget(
|
ButtonWidget(
|
||||||
|
@ -164,10 +164,10 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
||||||
title: "Leave shared album?",
|
title: "Leave shared album?",
|
||||||
body: "Photos added by you will be removed from the album",
|
body: "Photos added by you will be removed from the album",
|
||||||
);
|
);
|
||||||
if (result != null && mounted) {
|
if (actionResult?.action != null && mounted) {
|
||||||
if (result == ButtonAction.error) {
|
if (actionResult!.action == ButtonAction.error) {
|
||||||
showGenericErrorDialog(context: context);
|
showGenericErrorDialog(context: context);
|
||||||
} else if (result == ButtonAction.first) {
|
} else if (actionResult.action == ButtonAction.first) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,7 +247,7 @@ Future<void> deleteFilesOnDeviceOnly(
|
||||||
|
|
||||||
Future<bool> deleteFromTrash(BuildContext context, List<File> files) async {
|
Future<bool> deleteFromTrash(BuildContext context, List<File> files) async {
|
||||||
bool didDeletionStart = false;
|
bool didDeletionStart = false;
|
||||||
final result = await showChoiceActionSheet(
|
final actionResult = await showChoiceActionSheet(
|
||||||
context,
|
context,
|
||||||
title: "Permanently delete?",
|
title: "Permanently delete?",
|
||||||
body: "This action cannot be undone",
|
body: "This action cannot be undone",
|
||||||
|
@ -270,19 +270,20 @@ Future<bool> deleteFromTrash(BuildContext context, List<File> files) async {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (result == ButtonAction.error) {
|
|
||||||
|
if (actionResult?.action == null ||
|
||||||
|
actionResult!.action == ButtonAction.cancel) {
|
||||||
|
return didDeletionStart ? true : false;
|
||||||
|
} else if (actionResult.action == ButtonAction.error) {
|
||||||
await showGenericErrorDialog(context: context);
|
await showGenericErrorDialog(context: context);
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
if (result == null || result == ButtonAction.cancel) {
|
|
||||||
return didDeletionStart ? true : false;
|
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> emptyTrash(BuildContext context) async {
|
Future<bool> emptyTrash(BuildContext context) async {
|
||||||
final result = await showChoiceActionSheet(
|
final actionResult = await showChoiceActionSheet(
|
||||||
context,
|
context,
|
||||||
title: "Empty trash?",
|
title: "Empty trash?",
|
||||||
body:
|
body:
|
||||||
|
@ -298,11 +299,11 @@ Future<bool> emptyTrash(BuildContext context) async {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (result == ButtonAction.error) {
|
if (actionResult?.action == null ||
|
||||||
await showGenericErrorDialog(context: context);
|
actionResult!.action == ButtonAction.cancel) {
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if (actionResult.action == ButtonAction.error) {
|
||||||
if (result == null || result == ButtonAction.cancel) {
|
await showGenericErrorDialog(context: context);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -467,7 +468,7 @@ Future<List<String>> _tryDeleteSharedMediaFiles(List<String> localIDs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> shouldProceedWithDeletion(BuildContext context) async {
|
Future<bool> shouldProceedWithDeletion(BuildContext context) async {
|
||||||
final choice = await showChoiceActionSheet(
|
final actionResult = await showChoiceActionSheet(
|
||||||
context,
|
context,
|
||||||
title: "Permanently delete from device?",
|
title: "Permanently delete from device?",
|
||||||
body:
|
body:
|
||||||
|
@ -475,10 +476,10 @@ Future<bool> shouldProceedWithDeletion(BuildContext context) async {
|
||||||
firstButtonLabel: "Delete",
|
firstButtonLabel: "Delete",
|
||||||
isCritical: true,
|
isCritical: true,
|
||||||
);
|
);
|
||||||
if (choice == null) {
|
if (actionResult?.action == null) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return choice == ButtonAction.first;
|
return actionResult!.action == ButtonAction.first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,8 +529,14 @@ Future<void> showDeleteSheet(
|
||||||
await deleteFilesFromRemoteOnly(
|
await deleteFilesFromRemoteOnly(
|
||||||
context,
|
context,
|
||||||
selectedFiles.files.toList(),
|
selectedFiles.files.toList(),
|
||||||
|
).then(
|
||||||
|
(value) {
|
||||||
|
showShortToast(context, "Moved to trash");
|
||||||
|
},
|
||||||
|
onError: (e, s) {
|
||||||
|
showGenericErrorDialog(context: context);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
showShortToast(context, "Moved to trash");
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -581,14 +588,15 @@ Future<void> showDeleteSheet(
|
||||||
isInAlert: true,
|
isInAlert: true,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final ButtonAction? result = await showActionSheet(
|
final actionResult = await showActionSheet(
|
||||||
context: context,
|
context: context,
|
||||||
buttons: buttons,
|
buttons: buttons,
|
||||||
actionSheetType: ActionSheetType.defaultActionSheet,
|
actionSheetType: ActionSheetType.defaultActionSheet,
|
||||||
body: body,
|
body: body,
|
||||||
bodyHighlight: bodyHighlight,
|
bodyHighlight: bodyHighlight,
|
||||||
);
|
);
|
||||||
if (result != null && result == ButtonAction.error) {
|
if (actionResult?.action != null &&
|
||||||
|
actionResult!.action == ButtonAction.error) {
|
||||||
showGenericErrorDialog(context: context);
|
showGenericErrorDialog(context: context);
|
||||||
} else {
|
} else {
|
||||||
selectedFiles.clearAll();
|
selectedFiles.clearAll();
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:math';
|
||||||
import 'package:confetti/confetti.dart';
|
import 'package:confetti/confetti.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:photos/core/constants.dart';
|
import 'package:photos/core/constants.dart';
|
||||||
|
import "package:photos/models/search/button_result.dart";
|
||||||
import 'package:photos/ui/common/loading_widget.dart';
|
import 'package:photos/ui/common/loading_widget.dart';
|
||||||
import 'package:photos/ui/common/progress_dialog.dart';
|
import 'package:photos/ui/common/progress_dialog.dart';
|
||||||
import 'package:photos/ui/components/action_sheet_widget.dart';
|
import 'package:photos/ui/components/action_sheet_widget.dart';
|
||||||
|
@ -135,7 +136,7 @@ Future<ButtonAction?> showChoiceDialog(
|
||||||
}
|
}
|
||||||
|
|
||||||
///Will return null if dismissed by tapping outside
|
///Will return null if dismissed by tapping outside
|
||||||
Future<ButtonAction?> showChoiceActionSheet(
|
Future<ButtonResult?> showChoiceActionSheet(
|
||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
required String title,
|
required String title,
|
||||||
String? body,
|
String? body,
|
||||||
|
|
Loading…
Add table
Reference in a new issue