Ensure widget is still mounted before showing popup

OmarHatem committed Feb 6, 2023 at 19:08 UTC 03f55445457251e366c5c5501e5b198aa5ccf99f
1 file changed +12 -10
lib/src/screens/send/send_page.dart
+12 -10
@@ -339,7 +339,7 @@ class SendPage extends BasePage {
339 showErrorValidationAlert(context);
340 return;
341 }
342 -
342 +
343 await sendViewModel.createTransaction();
344
345 },
@@ -365,15 +365,17 @@ class SendPage extends BasePage {
365 reaction((_) => sendViewModel.state, (ExecutionState state) {
366 if (state is FailureState) {
367 WidgetsBinding.instance.addPostFrameCallback((_) {
368 - showPopUp<void>(
369 - context: context,
370 - builder: (BuildContext context) {
371 - return AlertWithOneAction(
372 - alertTitle: S.of(context).error,
373 - alertContent: state.error,
374 - buttonText: S.of(context).ok,
375 - buttonAction: () => Navigator.of(context).pop());
376 - });
368 + if (context.mounted) {
369 + showPopUp<void>(
370 + context: context,
371 + builder: (BuildContext context) {
372 + return AlertWithOneAction(
373 + alertTitle: S.of(context).error,
374 + alertContent: state.error,
375 + buttonText: S.of(context).ok,
376 + buttonAction: () => Navigator.of(context).pop());
377 + });
378 + }
379 });
380 }
381