desktop delete routing fixes

This commit is contained in:
julian 2022-11-21 14:52:41 -06:00
parent 04b982fb25
commit f75e4ea2fa
3 changed files with 207 additions and 137 deletions

View file

@ -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<DeleteWalletButton> {
@override
void initState() {
walletId = widget.walletId;
final managerProvider =
ref.read(walletsChangeNotifierProvider).getManagerProvider(walletId);
super.initState();
}
@ -38,25 +36,45 @@ class _DeleteWalletButton extends ConsumerState<DeleteWalletButton> {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(1000),
),
onPressed: () {
showDialog<void>(
onPressed: () async {
final shouldOpenDeleteDialog = await showDialog<bool?>(
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<bool?>(
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<DeleteWalletButton> {
);
}
}
class DeletePopupButton extends StatefulWidget {
const DeletePopupButton({
Key? key,
this.onTap,
}) : super(key: key);
final VoidCallback? onTap;
@override
State<DeletePopupButton> createState() => _DeletePopupButtonState();
}
class _DeletePopupButtonState extends State<DeletePopupButton> {
@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<StackColors>()!
.standardBoxShadow,
],
),
child: Text(
"Delete",
style: STextStyles.desktopButtonSecondaryEnabled(context),
),
),
),
),
),
],
);
}
}

View file

@ -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<DeleteWalletKeysPopup> {
),
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<DeleteWalletKeysPopup> {
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<void>.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<DeleteWalletKeysPopup> {
);
}
}
class ConfirmDelete extends ConsumerStatefulWidget {
const ConfirmDelete({
Key? key,
required this.walletId,
}) : super(key: key);
final String walletId;
@override
ConsumerState<ConfirmDelete> createState() => _ConfirmDeleteState();
}
class _ConfirmDeleteState extends ConsumerState<ConfirmDelete> {
@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<void>.delayed(const Duration(seconds: 1));
walletsInstance.removeWallet(walletId: _managerWalletId);
},
),
],
),
],
),
],
),
);
}
}

View file

@ -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,
),
);
}
},
),
],