diff --git a/lib/src/screens/base_page.dart b/lib/src/screens/base_page.dart index 20c918be6..bf60525e4 100644 --- a/lib/src/screens/base_page.dart +++ b/lib/src/screens/base_page.dart @@ -1,4 +1,5 @@ import 'package:cake_wallet/themes/theme_base.dart'; +import 'package:cake_wallet/utils/route_aware.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/di.dart'; @@ -32,6 +33,14 @@ abstract class BasePage extends StatelessWidget { Widget? get endDrawer => null; + Function(BuildContext context)? get pushToWidget => null; + + Function(BuildContext context)? get pushToNextWidget => null; + + Function(BuildContext context)? get popWidget => null; + + Function(BuildContext context)? get popNextWidget => null; + AppBarStyle get appBarStyle => AppBarStyle.regular; Widget Function(BuildContext, Widget)? get rootWrapper => null; @@ -162,15 +171,21 @@ abstract class BasePage extends StatelessWidget { @override Widget build(BuildContext context) { - final root = Scaffold( - key: _scaffoldKey, - backgroundColor: pageBackgroundColor(context), - resizeToAvoidBottomInset: resizeToAvoidBottomInset, - extendBodyBehindAppBar: extendBodyBehindAppBar, - endDrawer: endDrawer, - appBar: appBar(context), - body: body(context), - floatingActionButton: floatingActionButton(context)); + final root = RouteAwareWidget( + child: Scaffold( + key: _scaffoldKey, + backgroundColor: pageBackgroundColor(context), + resizeToAvoidBottomInset: resizeToAvoidBottomInset, + extendBodyBehindAppBar: extendBodyBehindAppBar, + endDrawer: endDrawer, + appBar: appBar(context), + body: body(context), + floatingActionButton: floatingActionButton(context)), + pushToWidget: (context) => pushToWidget?.call(context), + pushToNextWidget: (context) => pushToNextWidget?.call(context), + popWidget: (context) => popWidget?.call(context), + popNextWidget: (context) => popNextWidget?.call(context), + ); return rootWrapper?.call(context, root) ?? root; } diff --git a/lib/src/screens/exchange/exchange_page.dart b/lib/src/screens/exchange/exchange_page.dart index e2d424fa0..5c064df27 100644 --- a/lib/src/screens/exchange/exchange_page.dart +++ b/lib/src/screens/exchange/exchange_page.dart @@ -99,6 +99,14 @@ class ExchangePage extends BasePage { @override AppBarStyle get appBarStyle => AppBarStyle.transparent; + @override + Function(BuildContext)? get pushToNextWidget => (context) { + FocusScopeNode currentFocus = FocusScope.of(context); + if (!currentFocus.hasPrimaryFocus) { + currentFocus.focusedChild?.unfocus(); + } + }; + @override Widget middle(BuildContext context) => Row( mainAxisAlignment: MainAxisAlignment.center, diff --git a/lib/src/screens/ionia/cards/ionia_gift_card_detail_page.dart b/lib/src/screens/ionia/cards/ionia_gift_card_detail_page.dart index dba78f557..dcd1d54b4 100644 --- a/lib/src/screens/ionia/cards/ionia_gift_card_detail_page.dart +++ b/lib/src/screens/ionia/cards/ionia_gift_card_detail_page.dart @@ -84,12 +84,7 @@ class IoniaGiftCardDetailPage extends BasePage { } }); - return RouteAwareWidget( - pushToWidget: ()=> viewModel.increaseBrightness(), - pushToNextWidget: ()=> DeviceDisplayBrightness.setBrightness(viewModel.brightness), - popNextWidget: ()=> viewModel.increaseBrightness(), - popWidget: ()=> DeviceDisplayBrightness.setBrightness(viewModel.brightness), - child: ScrollableWithBottomSection( + return ScrollableWithBottomSection( contentPadding: EdgeInsets.all(24), content: Column( children: [ @@ -168,7 +163,7 @@ class IoniaGiftCardDetailPage extends BasePage { }, ), ), - )); + ); } Widget buildIoniaTile(BuildContext context, {required String title, required String subTitle}) { diff --git a/lib/src/screens/new_wallet/new_wallet_page.dart b/lib/src/screens/new_wallet/new_wallet_page.dart index 8cc8a138d..8d46827eb 100644 --- a/lib/src/screens/new_wallet/new_wallet_page.dart +++ b/lib/src/screens/new_wallet/new_wallet_page.dart @@ -38,6 +38,14 @@ class NewWalletPage extends BasePage { @override String get title => S.current.new_wallet; + @override + Function(BuildContext)? get pushToNextWidget => (context) { + FocusScopeNode currentFocus = FocusScope.of(context); + if (!currentFocus.hasPrimaryFocus) { + currentFocus.focusedChild?.unfocus(); + } + }; + @override Widget body(BuildContext context) => WalletNameForm( _walletNewVM, diff --git a/lib/src/screens/new_wallet/new_wallet_type_page.dart b/lib/src/screens/new_wallet/new_wallet_type_page.dart index dc22a60db..65c7bd59b 100644 --- a/lib/src/screens/new_wallet/new_wallet_type_page.dart +++ b/lib/src/screens/new_wallet/new_wallet_type_page.dart @@ -34,6 +34,14 @@ class NewWalletTypePage extends BasePage { String get title => isCreate ? S.current.wallet_list_create_new_wallet : S.current.wallet_list_restore_wallet; + @override + Function(BuildContext)? get pushToNextWidget => (context) { + FocusScopeNode currentFocus = FocusScope.of(context); + if (!currentFocus.hasPrimaryFocus) { + currentFocus.focusedChild?.unfocus(); + } + }; + @override Widget body(BuildContext context) => WalletTypeForm( onTypeSelected: onTypeSelected, diff --git a/lib/src/screens/restore/restore_from_backup_page.dart b/lib/src/screens/restore/restore_from_backup_page.dart index f7fddac3f..c5bc2a163 100644 --- a/lib/src/screens/restore/restore_from_backup_page.dart +++ b/lib/src/screens/restore/restore_from_backup_page.dart @@ -21,6 +21,14 @@ class RestoreFromBackupPage extends BasePage { @override String get title => S.current.restore_title_from_backup; + @override + Function(BuildContext)? get pushToNextWidget => (context) { + FocusScopeNode currentFocus = FocusScope.of(context); + if (!currentFocus.hasPrimaryFocus) { + currentFocus.focusedChild?.unfocus(); + } + }; + @override Widget body(BuildContext context) { reaction((_) => restoreFromBackupViewModel.state, (ExecutionState state) { diff --git a/lib/src/screens/restore/wallet_restore_page.dart b/lib/src/screens/restore/wallet_restore_page.dart index 6fcacfb0a..8e6ee0983 100644 --- a/lib/src/screens/restore/wallet_restore_page.dart +++ b/lib/src/screens/restore/wallet_restore_page.dart @@ -101,6 +101,14 @@ class WalletRestorePage extends BasePage { // String? derivationPath = null; DerivationInfo? derivationInfo; + @override + Function(BuildContext)? get pushToNextWidget => (context) { + FocusScopeNode currentFocus = FocusScope.of(context); + if (!currentFocus.hasPrimaryFocus) { + currentFocus.focusedChild?.unfocus(); + } + }; + @override Widget body(BuildContext context) { reaction((_) => walletRestoreViewModel.state, (ExecutionState state) { diff --git a/lib/src/screens/send/send_page.dart b/lib/src/screens/send/send_page.dart index 438c22c1d..b46a7f3db 100644 --- a/lib/src/screens/send/send_page.dart +++ b/lib/src/screens/send/send_page.dart @@ -66,6 +66,14 @@ class SendPage extends BasePage { @override bool get extendBodyBehindAppBar => true; + @override + Function(BuildContext)? get pushToNextWidget => (context) { + FocusScopeNode currentFocus = FocusScope.of(context); + if (!currentFocus.hasPrimaryFocus) { + currentFocus.focusedChild?.unfocus(); + } + }; + @override Widget? leading(BuildContext context) { final _backButton = Icon( diff --git a/lib/src/screens/send/send_template_page.dart b/lib/src/screens/send/send_template_page.dart index 52458942c..76414ecb2 100644 --- a/lib/src/screens/send/send_template_page.dart +++ b/lib/src/screens/send/send_template_page.dart @@ -32,6 +32,14 @@ class SendTemplatePage extends BasePage { @override AppBarStyle get appBarStyle => AppBarStyle.transparent; + @override + Function(BuildContext)? get pushToNextWidget => (context) { + FocusScopeNode currentFocus = FocusScope.of(context); + if (!currentFocus.hasPrimaryFocus) { + currentFocus.focusedChild?.unfocus(); + } + }; + @override Widget trailing(context) => Observer(builder: (_) { return sendTemplateViewModel.recipients.length > 1 diff --git a/lib/utils/route_aware.dart b/lib/utils/route_aware.dart index 28c72c4a4..d1721d912 100644 --- a/lib/utils/route_aware.dart +++ b/lib/utils/route_aware.dart @@ -10,10 +10,10 @@ class RouteAwareWidget extends StatefulWidget { this.popNextWidget}); final Widget child; - final Function()? pushToWidget; - final Function()? pushToNextWidget; - final Function()? popWidget; - final Function()? popNextWidget; + final Function(BuildContext context)? pushToWidget; + final Function(BuildContext context)? pushToNextWidget; + final Function(BuildContext context)? popWidget; + final Function(BuildContext context)? popNextWidget; @override State createState() => RouteAwareWidgetState(); @@ -35,28 +35,28 @@ class RouteAwareWidgetState extends State with RouteAware { @override void didPush() { if (widget.pushToWidget != null) { - widget.pushToWidget!(); + widget.pushToWidget!(context); } } @override void didPushNext() { if (widget.pushToNextWidget != null) { - widget.pushToNextWidget!(); + widget.pushToNextWidget!(context); } } @override void didPop() { if (widget.popWidget != null) { - widget.popWidget!(); + widget.popWidget!(context); } } @override void didPopNext() { if (widget.popNextWidget != null) { - widget.popNextWidget!(); + widget.popNextWidget!(context); } }