From fa54ebe855bcb2d18cd47df70aff3394374bbb7c Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Wed, 8 Feb 2023 17:01:23 +0200 Subject: [PATCH] Fix popup null context as it was using a dismissed (unmounted) context [skip ci] --- .../exchange_trade/exchange_trade_page.dart | 232 +++++++++--------- lib/utils/show_pop_up.dart | 19 +- 2 files changed, 126 insertions(+), 125 deletions(-) diff --git a/lib/src/screens/exchange_trade/exchange_trade_page.dart b/lib/src/screens/exchange_trade/exchange_trade_page.dart index 1fe4983f6..f56ae6b2a 100644 --- a/lib/src/screens/exchange_trade/exchange_trade_page.dart +++ b/lib/src/screens/exchange_trade/exchange_trade_page.dart @@ -112,7 +112,7 @@ class ExchangeTradeState extends State { width: 16, color: Theme.of(context).primaryTextTheme!.overline!.color!); - _setEffects(context); + _setEffects(); return Container( child: ScrollableWithBottomSection( @@ -234,7 +234,7 @@ class ExchangeTradeState extends State { ); } - void _setEffects(BuildContext context) { + void _setEffects() { if (_effectsInstalled) { return; } @@ -245,12 +245,12 @@ class ExchangeTradeState extends State { WidgetsBinding.instance.addPostFrameCallback((_) { showPopUp( context: context, - builder: (BuildContext context) { + builder: (BuildContext popupContext) { return AlertWithOneAction( - alertTitle: S.of(context).error, + alertTitle: S.of(popupContext).error, alertContent: state.error, - buttonText: S.of(context).ok, - buttonAction: () => Navigator.of(context).pop()); + buttonText: S.of(popupContext).ok, + buttonAction: () => Navigator.of(popupContext).pop()); }); }); } @@ -259,118 +259,24 @@ class ExchangeTradeState extends State { WidgetsBinding.instance.addPostFrameCallback((_) { showPopUp( context: context, - builder: (BuildContext context) { + builder: (BuildContext popupContext) { return ConfirmSendingAlert( - alertTitle: S.of(context).confirm_sending, - amount: S.of(context).send_amount, + alertTitle: S.of(popupContext).confirm_sending, + amount: S.of(popupContext).send_amount, amountValue: widget.exchangeTradeViewModel.sendViewModel .pendingTransaction!.amountFormatted, - fee: S.of(context).send_fee, + fee: S.of(popupContext).send_fee, feeValue: widget.exchangeTradeViewModel.sendViewModel .pendingTransaction!.feeFormatted, - rightButtonText: S.of(context).ok, - leftButtonText: S.of(context).cancel, + rightButtonText: S.of(popupContext).ok, + leftButtonText: S.of(popupContext).cancel, actionRightButton: () async { - Navigator.of(context).pop(); + Navigator.of(popupContext).pop(); await widget.exchangeTradeViewModel.sendViewModel .commitTransaction(); - await showPopUp( - context: context, - builder: (BuildContext context) { - return Observer(builder: (_) { - final state = widget - .exchangeTradeViewModel.sendViewModel.state; - - if (state is TransactionCommitted) { - return Stack( - children: [ - Container( - color: Theme.of(context).backgroundColor, - child: Center( - child: Image.asset( - 'assets/images/birthday_cake.png'), - ), - ), - Center( - child: Padding( - padding: EdgeInsets.only( - top: 220, left: 24, right: 24), - child: Text( - S.of(context).send_success(widget - .exchangeTradeViewModel - .wallet - .currency - .toString()), - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 22, - fontWeight: FontWeight.bold, - color: Theme.of(context) - .primaryTextTheme! - .headline6! - .color, - decoration: TextDecoration.none, - ), - ), - ), - ), - Positioned( - left: 24, - right: 24, - bottom: 24, - child: PrimaryButton( - onPressed: () => - Navigator.of(context).pop(), - text: S.of(context).send_got_it, - color: Theme.of(context) - .accentTextTheme! - .bodyText1! - .color!, - textColor: Colors.white)) - ], - ); - } - - return Stack( - children: [ - Container( - color: Theme.of(context).backgroundColor, - child: Center( - child: Image.asset( - 'assets/images/birthday_cake.png'), - ), - ), - BackdropFilter( - filter: ImageFilter.blur( - sigmaX: 3.0, sigmaY: 3.0), - child: Container( - decoration: BoxDecoration( - color: Theme.of(context) - .backgroundColor - .withOpacity(0.25)), - child: Center( - child: Padding( - padding: EdgeInsets.only(top: 220), - child: Text( - S.of(context).send_sending, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 22, - fontWeight: FontWeight.bold, - color: Theme.of(context).primaryTextTheme!.headline6!.color!, - decoration: TextDecoration.none, - ), - ), - ), - ), - ), - ) - ], - ); - }); - }); + transactionStatePopup(); }, - actionLeftButton: () => Navigator.of(context).pop(), + actionLeftButton: () => Navigator.of(popupContext).pop(), feeFiatAmount: widget.exchangeTradeViewModel .pendingTransactionFeeFiatAmountFormatted, fiatAmountValue: widget.exchangeTradeViewModel @@ -385,12 +291,12 @@ class ExchangeTradeState extends State { WidgetsBinding.instance.addPostFrameCallback((_) { showPopUp( context: context, - builder: (BuildContext context) { + builder: (BuildContext popupContext) { return AlertWithOneAction( - alertTitle: S.of(context).sending, - alertContent: S.of(context).transaction_sent, - buttonText: S.of(context).ok, - buttonAction: () => Navigator.of(context).pop()); + alertTitle: S.of(popupContext).sending, + alertContent: S.of(popupContext).transaction_sent, + buttonText: S.of(popupContext).ok, + buttonAction: () => Navigator.of(popupContext).pop()); }); }); } @@ -398,4 +304,102 @@ class ExchangeTradeState extends State { _effectsInstalled = true; } + + transactionStatePopup() { + showPopUp( + context: context, + builder: (BuildContext popupContext) { + return Observer(builder: (_) { + final state = widget + .exchangeTradeViewModel.sendViewModel.state; + + if (state is TransactionCommitted) { + return Stack( + children: [ + Container( + color: Theme.of(popupContext).backgroundColor, + child: Center( + child: Image.asset( + 'assets/images/birthday_cake.png'), + ), + ), + Center( + child: Padding( + padding: EdgeInsets.only( + top: 220, left: 24, right: 24), + child: Text( + S.of(popupContext).send_success(widget + .exchangeTradeViewModel + .wallet + .currency + .toString()), + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + color: Theme.of(popupContext) + .primaryTextTheme! + .headline6! + .color, + decoration: TextDecoration.none, + ), + ), + ), + ), + Positioned( + left: 24, + right: 24, + bottom: 24, + child: PrimaryButton( + onPressed: () => + Navigator.of(popupContext).pop(), + text: S.of(popupContext).send_got_it, + color: Theme.of(popupContext) + .accentTextTheme! + .bodyText1! + .color!, + textColor: Colors.white)) + ], + ); + } + + return Stack( + children: [ + Container( + color: Theme.of(popupContext).backgroundColor, + child: Center( + child: Image.asset( + 'assets/images/birthday_cake.png'), + ), + ), + BackdropFilter( + filter: ImageFilter.blur( + sigmaX: 3.0, sigmaY: 3.0), + child: Container( + decoration: BoxDecoration( + color: Theme.of(popupContext) + .backgroundColor + .withOpacity(0.25)), + child: Center( + child: Padding( + padding: EdgeInsets.only(top: 220), + child: Text( + S.of(popupContext).send_sending, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + color: Theme.of(popupContext).primaryTextTheme!.headline6!.color!, + decoration: TextDecoration.none, + ), + ), + ), + ), + ), + ) + ], + ); + }); + }); + } } diff --git a/lib/utils/show_pop_up.dart b/lib/utils/show_pop_up.dart index 66748f6c2..d9bc26162 100644 --- a/lib/utils/show_pop_up.dart +++ b/lib/utils/show_pop_up.dart @@ -9,15 +9,12 @@ Future showPopUp({ bool useRootNavigator = true, RouteSettings? routeSettings }) async { - if (context.mounted) { - return showDialog( - context: context, - builder: builder, - barrierDismissible: barrierDismissible, - barrierColor: barrierColor, - useSafeArea: useSafeArea, - useRootNavigator: useRootNavigator, - routeSettings: routeSettings); - } - return null; + return showDialog( + context: context, + builder: builder, + barrierDismissible: barrierDismissible, + barrierColor: barrierColor, + useSafeArea: useSafeArea, + useRootNavigator: useRootNavigator, + routeSettings: routeSettings); }