From f75e4ea2faf8e71c385aa05732ace062ee90a324 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 21 Nov 2022 14:52:41 -0600 Subject: [PATCH] desktop delete routing fixes --- .../sub_widgets/delete_wallet_button.dart | 113 ++++++++-- .../sub_widgets/delete_wallet_keys_popup.dart | 204 +++++++++--------- .../desktop_attention_delete_wallet.dart | 27 ++- 3 files changed, 207 insertions(+), 137 deletions(-) diff --git a/lib/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/delete_wallet_button.dart b/lib/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/delete_wallet_button.dart index 54f991c37..fd401d613 100644 --- a/lib/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/delete_wallet_button.dart +++ b/lib/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/delete_wallet_button.dart @@ -1,13 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; -import 'package:stackwallet/providers/global/wallets_provider.dart'; +import 'package:stackwallet/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/desktop_delete_wallet_dialog.dart'; import 'package:stackwallet/route_generator.dart'; import 'package:stackwallet/utilities/assets.dart'; +import 'package:stackwallet/utilities/constants.dart'; +import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; -import 'desktop_delete_wallet_dialog.dart'; - class DeleteWalletButton extends ConsumerStatefulWidget { const DeleteWalletButton({ Key? key, @@ -26,8 +26,6 @@ class _DeleteWalletButton extends ConsumerState { @override void initState() { walletId = widget.walletId; - final managerProvider = - ref.read(walletsChangeNotifierProvider).getManagerProvider(walletId); super.initState(); } @@ -38,25 +36,45 @@ class _DeleteWalletButton extends ConsumerState { shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(1000), ), - onPressed: () { - showDialog( + onPressed: () async { + final shouldOpenDeleteDialog = await showDialog( context: context, - barrierDismissible: false, - builder: (context) => Navigator( - initialRoute: DesktopDeleteWalletDialog.routeName, - onGenerateRoute: RouteGenerator.generateRoute, - onGenerateInitialRoutes: (_, __) { - return [ - RouteGenerator.generateRoute( - RouteSettings( - name: DesktopDeleteWalletDialog.routeName, - arguments: walletId, - ), - ) - ]; - }, - ), + barrierColor: Colors.transparent, + builder: (context) { + return DeletePopupButton( + onTap: () async { + Navigator.of(context).pop(true); + }, + ); + }, ); + + if (shouldOpenDeleteDialog == true) { + final result = await showDialog( + context: context, + barrierDismissible: false, + builder: (context) => Navigator( + initialRoute: DesktopDeleteWalletDialog.routeName, + onGenerateRoute: RouteGenerator.generateRoute, + onGenerateInitialRoutes: (_, __) { + return [ + RouteGenerator.generateRoute( + RouteSettings( + name: DesktopDeleteWalletDialog.routeName, + arguments: walletId, + ), + ), + ]; + }, + ), + ); + + if (result == true) { + if (mounted) { + Navigator.of(context).pop(); + } + } + } }, child: Padding( padding: const EdgeInsets.symmetric( @@ -79,3 +97,54 @@ class _DeleteWalletButton extends ConsumerState { ); } } + +class DeletePopupButton extends StatefulWidget { + const DeletePopupButton({ + Key? key, + this.onTap, + }) : super(key: key); + + final VoidCallback? onTap; + + @override + State createState() => _DeletePopupButtonState(); +} + +class _DeletePopupButtonState extends State { + @override + Widget build(BuildContext context) { + return Stack( + children: [ + Positioned( + top: 24, + left: MediaQuery.of(context).size.width - 234, + child: MouseRegion( + cursor: SystemMouseCursors.click, + child: GestureDetector( + onTap: widget.onTap, + child: Container( + width: 210, + height: 70, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular( + Constants.size.circularBorderRadius, + ), + color: Colors.red, + boxShadow: [ + Theme.of(context) + .extension()! + .standardBoxShadow, + ], + ), + child: Text( + "Delete", + style: STextStyles.desktopButtonSecondaryEnabled(context), + ), + ), + ), + ), + ), + ], + ); + } +} diff --git a/lib/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/delete_wallet_keys_popup.dart b/lib/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/delete_wallet_keys_popup.dart index f70c2eadf..6b638bb75 100644 --- a/lib/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/delete_wallet_keys_popup.dart +++ b/lib/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/delete_wallet_keys_popup.dart @@ -1,11 +1,9 @@ -import 'dart:async'; - import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/pages/add_wallet_views/new_wallet_recovery_phrase_view/sub_widgets/mnemonic_table.dart'; -import 'package:stackwallet/pages_desktop_specific/home/my_stack_view/my_stack_view.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/providers/global/wallets_service_provider.dart'; +import 'package:stackwallet/route_generator.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; @@ -61,8 +59,10 @@ class _DeleteWalletKeysPopup extends ConsumerState { ), DesktopDialogCloseButton( onPressedOverride: () { - int count = 0; - Navigator.of(context).popUntil((_) => count++ >= 2); + Navigator.of( + context, + rootNavigator: true, + ).pop(); }, ), ], @@ -117,106 +117,17 @@ class _DeleteWalletKeysPopup extends ConsumerState { child: PrimaryButton( label: "Continue", onPressed: () async { - int count = 0; - Navigator.of(context).popUntil((_) => count++ >= 2); - - unawaited( - showDialog( - context: context, - builder: (context) { - return DesktopDialog( - maxHeight: 350, - child: Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - DesktopDialogCloseButton( - onPressedOverride: () { - int count = 0; - Navigator.of(context) - .popUntil((_) => count++ >= 2); - }, - ), - ], - ), - Column( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Text( - "Thanks! " - "\n\nYour wallet will be deleted.", - style: STextStyles.desktopH2(context), - textAlign: TextAlign.center, - ), - const SizedBox(height: 50), - Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - SecondaryButton( - width: 250, - buttonHeight: ButtonHeight.xl, - label: "Cancel", - onPressed: () { - int count = 0; - Navigator.of(context) - .popUntil( - (_) => count++ >= 2); - }), - const SizedBox(width: 16), - PrimaryButton( - width: 250, - buttonHeight: ButtonHeight.xl, - label: "Continue", - onPressed: () async { - // int count = 0; - // Navigator.of(context) - // .popUntil( - // (_) => count++ >= 2); - - final walletsInstance = ref.read( - walletsChangeNotifierProvider); - final manager = ref - .read( - walletsChangeNotifierProvider) - .getManager(_walletId); - - final _managerWalletId = - manager.walletId; - - await ref - .read( - walletsServiceChangeNotifierProvider) - .deleteWallet( - manager.walletName, - true); - - if (mounted) { - Navigator.of(context) - .popUntil( - ModalRoute.withName( - MyStackView - .routeName)); - } - - // wait for widget tree to dispose of any widgets watching the manager - await Future.delayed( - const Duration( - seconds: 1)); - walletsInstance.removeWallet( - walletId: - _managerWalletId); - }), - ], - ) - ], - ), - ], - ), - ); - }), + await Navigator.of(context).push( + RouteGenerator.getRoute( + builder: (context) { + return ConfirmDelete( + walletId: _walletId, + ); + }, + settings: const RouteSettings( + name: "/desktopConfirmDelete", + ), + ), ); }, ), @@ -232,3 +143,86 @@ class _DeleteWalletKeysPopup extends ConsumerState { ); } } + +class ConfirmDelete extends ConsumerStatefulWidget { + const ConfirmDelete({ + Key? key, + required this.walletId, + }) : super(key: key); + + final String walletId; + + @override + ConsumerState createState() => _ConfirmDeleteState(); +} + +class _ConfirmDeleteState extends ConsumerState { + @override + Widget build(BuildContext context) { + return DesktopDialog( + maxHeight: 350, + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: const [ + DesktopDialogCloseButton(), + ], + ), + Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + "Thanks! " + "\n\nYour wallet will be deleted.", + style: STextStyles.desktopH2(context), + textAlign: TextAlign.center, + ), + const SizedBox(height: 50), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SecondaryButton( + width: 250, + buttonHeight: ButtonHeight.xl, + label: "Cancel", + onPressed: () { + Navigator.of(context, rootNavigator: true).pop(); + }, + ), + const SizedBox(width: 16), + PrimaryButton( + width: 250, + buttonHeight: ButtonHeight.xl, + label: "Continue", + onPressed: () async { + final walletsInstance = + ref.read(walletsChangeNotifierProvider); + final manager = ref + .read(walletsChangeNotifierProvider) + .getManager(widget.walletId); + + final _managerWalletId = manager.walletId; + // + await ref + .read(walletsServiceChangeNotifierProvider) + .deleteWallet(manager.walletName, true); + + if (mounted) { + Navigator.of(context, rootNavigator: true).pop(true); + } + + // wait for widget tree to dispose of any widgets watching the manager + await Future.delayed(const Duration(seconds: 1)); + walletsInstance.removeWallet(walletId: _managerWalletId); + }, + ), + ], + ), + ], + ), + ], + ), + ); + } +} diff --git a/lib/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/desktop_attention_delete_wallet.dart b/lib/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/desktop_attention_delete_wallet.dart index 30546f60b..6eb04502e 100644 --- a/lib/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/desktop_attention_delete_wallet.dart +++ b/lib/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/desktop_attention_delete_wallet.dart @@ -41,8 +41,10 @@ class _DesktopAttentionDeleteWallet children: [ DesktopDialogCloseButton( onPressedOverride: () { - int count = 0; - Navigator.of(context).popUntil((_) => count++ >= 2); + Navigator.of( + context, + rootNavigator: true, + ).pop(); }, ), ], @@ -87,8 +89,10 @@ class _DesktopAttentionDeleteWallet buttonHeight: ButtonHeight.xl, label: "Cancel", onPressed: () { - int count = 0; - Navigator.of(context).popUntil((_) => count++ >= 2); + Navigator.of( + context, + rootNavigator: true, + ).pop(); }, ), const SizedBox(width: 16), @@ -102,12 +106,15 @@ class _DesktopAttentionDeleteWallet .getManager(widget.walletId) .mnemonic; - await Navigator.of(context) - .pushNamed(DeleteWalletKeysPopup.routeName, - arguments: Tuple2( - widget.walletId, - words, - )); + if (mounted) { + await Navigator.of(context).pushNamed( + DeleteWalletKeysPopup.routeName, + arguments: Tuple2( + widget.walletId, + words, + ), + ); + } }, ), ],