Skip to content

Commit 89ccff1

Browse files
committed
fix: WillPopScope migration
Migrate the deprecated WillPopScope widget to PopScope across the app. Simple barrier dialogs become canPop: false/true. Cases that ran side effects or conditionally gated the pop move that work into onPopInvokedWithResult.
1 parent 51db6c7 commit 89ccff1

44 files changed

Lines changed: 212 additions & 221 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/pages/add_wallet_views/new_wallet_recovery_phrase_view/new_wallet_recovery_phrase_view.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ class _NewWalletRecoveryPhraseViewState
7676
super.initState();
7777
}
7878

79-
Future<bool> onWillPop() async {
79+
Future<void> onPopInvoked() async {
8080
await delete();
81-
return true;
81+
if (mounted) {
82+
Navigator.of(context).pop();
83+
}
8284
}
8385

8486
Future<void> delete() async {
@@ -104,8 +106,14 @@ class _NewWalletRecoveryPhraseViewState
104106
@override
105107
Widget build(BuildContext context) {
106108
debugPrint("BUILD: $runtimeType");
107-
return WillPopScope(
108-
onWillPop: onWillPop,
109+
return PopScope(
110+
canPop: false,
111+
onPopInvokedWithResult: (bool didPop, dynamic result) async {
112+
if (didPop) {
113+
return;
114+
}
115+
await onPopInvoked();
116+
},
109117
child: MasterScaffold(
110118
isDesktop: isDesktop,
111119
appBar: isDesktop

lib/pages/add_wallet_views/restore_wallet_view/confirm_recovery_dialog.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ class ConfirmRecoveryDialog extends StatelessWidget {
9292
),
9393
);
9494
} else {
95-
return WillPopScope(
96-
onWillPop: () async {
97-
return true;
98-
},
95+
return PopScope(
96+
canPop: true,
9997
child: StackDialog(
10098
title: "Are you ready?",
10199
message:

lib/pages/add_wallet_views/restore_wallet_view/sub_widgets/mnemonic_word_count_select_sheet.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ class MnemonicWordCountSelectSheet extends ConsumerWidget {
2323

2424
@override
2525
Widget build(BuildContext context, WidgetRef ref) {
26-
return WillPopScope(
27-
onWillPop: () async {
26+
return PopScope(
27+
canPop: false,
28+
onPopInvokedWithResult: (bool didPop, dynamic result) {
29+
if (didPop) {
30+
return;
31+
}
2832
final length = ref.read(mnemonicWordCountStateProvider.state).state;
2933
Navigator.of(context).pop(length);
30-
return false;
3134
},
3235
child: Container(
3336
decoration: BoxDecoration(

lib/pages/add_wallet_views/restore_wallet_view/sub_widgets/restore_failed_dialog.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ class _RestoreFailedDialogState extends ConsumerState<RestoreFailedDialog> {
5151

5252
@override
5353
Widget build(BuildContext context) {
54-
return WillPopScope(
55-
onWillPop: () async {
56-
return false;
57-
},
54+
return PopScope(
55+
canPop: false,
5856
child: StackDialog(
5957
title: "Restore failed",
6058
message: errorMessage,

lib/pages/add_wallet_views/restore_wallet_view/sub_widgets/restoring_dialog.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,8 @@ class _RestoringDialogState extends State<RestoringDialog> {
102102
),
103103
);
104104
} else {
105-
return WillPopScope(
106-
onWillPop: () async {
107-
return false;
108-
},
105+
return PopScope(
106+
canPop: false,
109107
child: StackDialog(
110108
title: "Restoring wallet",
111109
message: "This may take a while. Please do not exit this screen.",

lib/pages/add_wallet_views/select_wallet_for_sol_token_view.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ class _SelectWalletForSolTokenViewState
9191
}
9292
}
9393

94-
return WillPopScope(
95-
onWillPop: () async {
94+
return PopScope(
95+
canPop: true,
96+
onPopInvokedWithResult: (bool didPop, dynamic result) {
9697
ref.read(newSolWalletTriggerTempUntilHiveCompletelyDeleted.notifier).state = false;
97-
return true;
9898
},
9999
child: ConditionalParent(
100100
condition: !isDesktop,

lib/pages/add_wallet_views/select_wallet_for_token_view.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ class _SelectWalletForTokenViewState
9292
}
9393
}
9494

95-
return WillPopScope(
96-
onWillPop: () async {
95+
return PopScope(
96+
canPop: true,
97+
onPopInvokedWithResult: (bool didPop, dynamic result) {
9798
ref.read(createSpecialEthWalletRoutingFlag.notifier).state = false;
98-
return true;
9999
},
100100
child: ConditionalParent(
101101
condition: !isDesktop,

lib/pages/add_wallet_views/verify_recovery_phrase_view/verify_recovery_phrase_view.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,15 +458,14 @@ class _VerifyRecoveryPhraseViewState
458458
return Tuple2(result, chosenWord);
459459
}
460460

461-
Future<bool> onWillPop() async {
461+
Future<void> onPopInvoked() async {
462462
// await delete();
463463
Navigator.of(context).popUntil(
464464
ModalRoute.withName(
465465
// NewWalletRecoveryPhraseWarningView.routeName,
466466
NewWalletRecoveryPhraseView.routeName,
467467
),
468468
);
469-
return false;
470469
}
471470

472471
Future<void> delete() async {
@@ -482,8 +481,14 @@ class _VerifyRecoveryPhraseViewState
482481
.watch(verifyMnemonicWordIndexStateProvider.state)
483482
.state;
484483

485-
return WillPopScope(
486-
onWillPop: onWillPop,
484+
return PopScope(
485+
canPop: false,
486+
onPopInvokedWithResult: (bool didPop, dynamic result) async {
487+
if (didPop) {
488+
return;
489+
}
490+
await onPopInvoked();
491+
},
487492
child: MasterScaffold(
488493
isDesktop: isDesktop,
489494
appBar: isDesktop

lib/pages/buy_view/buy_form.dart

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,19 @@ class _BuyFormState extends ConsumerState<BuyForm> {
159159

160160
void selectCrypto() async {
161161
if (ref.read(simplexProvider).supportedCryptos.isEmpty) {
162-
bool shouldPop = false;
163162
unawaited(
164163
showDialog(
165164
context: context,
166-
builder: (context) => WillPopScope(
167-
child: const CustomLoadingOverlay(
165+
builder: (context) => const PopScope(
166+
canPop: false,
167+
child: CustomLoadingOverlay(
168168
message: "Loading currency data",
169169
eventBus: null,
170170
),
171-
onWillPop: () async => shouldPop,
172171
),
173172
),
174173
);
175174
await _loadSimplexCryptos();
176-
shouldPop = true;
177175
if (mounted) {
178176
Navigator.of(context, rootNavigator: isDesktop).pop();
179177
}
@@ -265,21 +263,19 @@ class _BuyFormState extends ConsumerState<BuyForm> {
265263

266264
Future<void> selectFiat() async {
267265
if (ref.read(simplexProvider).supportedFiats.isEmpty) {
268-
bool shouldPop = false;
269266
unawaited(
270267
showDialog(
271268
context: context,
272-
builder: (context) => WillPopScope(
273-
child: const CustomLoadingOverlay(
269+
builder: (context) => const PopScope(
270+
canPop: false,
271+
child: CustomLoadingOverlay(
274272
message: "Loading currency data",
275273
eventBus: null,
276274
),
277-
onWillPop: () async => shouldPop,
278275
),
279276
),
280277
);
281278
await _loadSimplexFiats();
282-
shouldPop = true;
283279
if (mounted) {
284280
Navigator.of(context, rootNavigator: isDesktop).pop();
285281
}
@@ -396,16 +392,15 @@ class _BuyFormState extends ConsumerState<BuyForm> {
396392
// }
397393

398394
Future<void> previewQuote(SimplexQuote quote) async {
399-
bool shouldPop = false;
400395
unawaited(
401396
showDialog(
402397
context: context,
403-
builder: (context) => WillPopScope(
404-
child: const CustomLoadingOverlay(
398+
builder: (context) => const PopScope(
399+
canPop: false,
400+
child: CustomLoadingOverlay(
405401
message: "Loading quote data",
406402
eventBus: null,
407403
),
408-
onWillPop: () async => shouldPop,
409404
),
410405
),
411406
);
@@ -425,7 +420,6 @@ class _BuyFormState extends ConsumerState<BuyForm> {
425420
);
426421

427422
final BuyResponse<SimplexQuote> quoteResponse = await _loadQuote(quote);
428-
shouldPop = true;
429423
if (mounted) {
430424
Navigator.of(context, rootNavigator: isDesktop).pop();
431425
}

lib/pages/cashfusion/fusion_progress_view.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,17 @@ class _FusionProgressViewState extends ConsumerState<FusionProgressView> {
118118

119119
WakelockPlus.enable();
120120

121-
return WillPopScope(
122-
onWillPop: () async {
123-
return await _requestAndProcessCancel();
121+
return PopScope(
122+
canPop: false,
123+
onPopInvokedWithResult: (bool didPop, dynamic result) async {
124+
if (didPop) {
125+
return;
126+
}
127+
if (await _requestAndProcessCancel()) {
128+
if (mounted) {
129+
Navigator.of(context).pop();
130+
}
131+
}
124132
},
125133
child: Background(
126134
child: Scaffold(

0 commit comments

Comments
 (0)