Explorar o código

Created a wrapper around showDialogWidet() for showing choiceDialogs

ashilkn %!s(int64=2) %!d(string=hai) anos
pai
achega
5daada33a9
Modificáronse 2 ficheiros con 55 adicións e 30 borrados
  1. 14 29
      lib/ui/account/delete_account_page.dart
  2. 41 1
      lib/ui/components/dialog_widget.dart

+ 14 - 29
lib/ui/account/delete_account_page.dart

@@ -11,7 +11,6 @@ import 'package:photos/services/user_service.dart';
 import 'package:photos/ui/common/gradient_button.dart';
 import 'package:photos/ui/components/button_widget.dart';
 import 'package:photos/ui/components/dialog_widget.dart';
-import 'package:photos/ui/components/models/button_type.dart';
 import 'package:photos/utils/crypto_util.dart';
 import 'package:photos/utils/dialog_util.dart';
 import 'package:photos/utils/email_util.dart';
@@ -154,39 +153,25 @@ class DeleteAccountPage extends StatelessWidget {
     );
 
     if (hasAuthenticated) {
-      final choice = await showDialogWidget(
+      final choice = await showNewChoiceDialog(
         context: context,
         title: 'Are you sure you want to delete your account?',
         body:
             'Your uploaded data will be scheduled for deletion, and your account'
             'will be permanently deleted. \n\nThis action is not reversible.',
-        buttons: [
-          ButtonWidget(
-            labelText: "Delete",
-            isInAlert: true,
-            buttonType: ButtonType.neutral,
-            buttonSize: ButtonSize.large,
-            buttonAction: ButtonAction.first,
-            onTap: () async {
-              final decryptChallenge = CryptoUtil.openSealSync(
-                Sodium.base642bin(response.encryptedChallenge),
-                Sodium.base642bin(
-                    Configuration.instance.getKeyAttributes().publicKey),
-                Configuration.instance.getSecretKey(),
-              );
-              final challengeResponseStr = utf8.decode(decryptChallenge);
-              await UserService.instance
-                  .deleteAccount(context, challengeResponseStr);
-            },
-          ),
-          const ButtonWidget(
-            labelText: "Cancel",
-            isInAlert: true,
-            buttonType: ButtonType.secondary,
-            buttonSize: ButtonSize.large,
-            buttonAction: ButtonAction.cancel,
-          ),
-        ],
+        firstButtonLabel: "Delete",
+        firstButtonOnTap: () async {
+          final decryptChallenge = CryptoUtil.openSealSync(
+            Sodium.base642bin(response.encryptedChallenge),
+            Sodium.base642bin(
+              Configuration.instance.getKeyAttributes().publicKey,
+            ),
+            Configuration.instance.getSecretKey(),
+          );
+          final challengeResponseStr = utf8.decode(decryptChallenge);
+          await UserService.instance
+              .deleteAccount(context, challengeResponseStr);
+        },
       );
       if (choice == ButtonAction.error) {
         showGenericErrorDialog(context);

+ 41 - 1
lib/ui/components/dialog_widget.dart

@@ -6,9 +6,49 @@ import 'package:photos/theme/colors.dart';
 import 'package:photos/theme/effects.dart';
 import 'package:photos/theme/ente_theme.dart';
 import 'package:photos/ui/components/button_widget.dart';
+import 'package:photos/ui/components/models/button_type.dart';
 import 'package:photos/utils/separators_util.dart';
 
-Future<dynamic> showDialogWidget({
+Future<ButtonAction?> showNewChoiceDialog({
+  required BuildContext context,
+  required String title,
+  required String body,
+  required String firstButtonLabel,
+  String secondButtonLabel = "Cancel",
+  ButtonType firstButtonType = ButtonType.neutral,
+  ButtonType secondButtonType = ButtonType.secondary,
+  ButtonAction firstButtonAction = ButtonAction.first,
+  ButtonAction secondButtonAction = ButtonAction.cancel,
+  FutureVoidCallback? firstButtonOnTap,
+  FutureVoidCallback? secondButtonOnTap,
+  bool isCritical = false,
+  IconData? icon,
+}) async {
+  final buttons = [
+    ButtonWidget(
+      buttonType: isCritical ? ButtonType.critical : firstButtonType,
+      labelText: firstButtonLabel,
+      isInAlert: true,
+      onTap: firstButtonOnTap,
+      buttonAction: firstButtonAction,
+    ),
+    ButtonWidget(
+      buttonType: secondButtonType,
+      labelText: secondButtonLabel,
+      isInAlert: true,
+      onTap: secondButtonOnTap,
+      buttonAction: secondButtonAction,
+    ),
+  ];
+  return showDialogWidget(
+    context: context,
+    title: title,
+    body: body,
+    buttons: buttons,
+  );
+}
+
+Future<ButtonAction?> showDialogWidget({
   required BuildContext context,
   required String title,
   required String body,