CW-636-1-Unfocus text fields when push to next one (#1460)

* unfocus text fields when push to next one * unfocus when push to next from new wallet / restore pages[skip ci]]

Serhii committed May 31, 2024 at 14:57 UTC 287c2d8b60c9095926ad8f361b5bcd6be4e0962e
10 files changed +90 -24
lib/src/screens/base_page.dart
+24 -9
@@ -1,4 +1,5 @@
1 import 'package:cake_wallet/themes/theme_base.dart';
2 +import 'package:cake_wallet/utils/route_aware.dart';
3 import 'package:flutter/cupertino.dart';
4 import 'package:flutter/material.dart';
5 import 'package:cake_wallet/di.dart';
@@ -32,6 +33,14 @@ abstract class BasePage extends StatelessWidget {
33
34 Widget? get endDrawer => null;
35
36 + Function(BuildContext context)? get pushToWidget => null;
37 +
38 + Function(BuildContext context)? get pushToNextWidget => null;
39 +
40 + Function(BuildContext context)? get popWidget => null;
41 +
42 + Function(BuildContext context)? get popNextWidget => null;
43 +
44 AppBarStyle get appBarStyle => AppBarStyle.regular;
45
46 Widget Function(BuildContext, Widget)? get rootWrapper => null;
@@ -162,15 +171,21 @@ abstract class BasePage extends StatelessWidget {
171
172 @override
173 Widget build(BuildContext context) {
165 - final root = Scaffold(
166 - key: _scaffoldKey,
167 - backgroundColor: pageBackgroundColor(context),
168 - resizeToAvoidBottomInset: resizeToAvoidBottomInset,
169 - extendBodyBehindAppBar: extendBodyBehindAppBar,
170 - endDrawer: endDrawer,
171 - appBar: appBar(context),
172 - body: body(context),
173 - floatingActionButton: floatingActionButton(context));
174 + final root = RouteAwareWidget(
175 + child: Scaffold(
176 + key: _scaffoldKey,
177 + backgroundColor: pageBackgroundColor(context),
178 + resizeToAvoidBottomInset: resizeToAvoidBottomInset,
179 + extendBodyBehindAppBar: extendBodyBehindAppBar,
180 + endDrawer: endDrawer,
181 + appBar: appBar(context),
182 + body: body(context),
183 + floatingActionButton: floatingActionButton(context)),
184 + pushToWidget: (context) => pushToWidget?.call(context),
185 + pushToNextWidget: (context) => pushToNextWidget?.call(context),
186 + popWidget: (context) => popWidget?.call(context),
187 + popNextWidget: (context) => popNextWidget?.call(context),
188 + );
189
190 return rootWrapper?.call(context, root) ?? root;
191 }
lib/src/screens/exchange/exchange_page.dart
+8
@@ -99,6 +99,14 @@ class ExchangePage extends BasePage {
99 @override
100 AppBarStyle get appBarStyle => AppBarStyle.transparent;
101
102 + @override
103 + Function(BuildContext)? get pushToNextWidget => (context) {
104 + FocusScopeNode currentFocus = FocusScope.of(context);
105 + if (!currentFocus.hasPrimaryFocus) {
106 + currentFocus.focusedChild?.unfocus();
107 + }
108 + };
109 +
110 @override
111 Widget middle(BuildContext context) => Row(
112 mainAxisAlignment: MainAxisAlignment.center,
lib/src/screens/ionia/cards/ionia_gift_card_detail_page.dart
+2 -7
@@ -84,12 +84,7 @@ class IoniaGiftCardDetailPage extends BasePage {
84 }
85 });
86
87 - return RouteAwareWidget(
88 - pushToWidget: ()=> viewModel.increaseBrightness(),
89 - pushToNextWidget: ()=> DeviceDisplayBrightness.setBrightness(viewModel.brightness),
90 - popNextWidget: ()=> viewModel.increaseBrightness(),
91 - popWidget: ()=> DeviceDisplayBrightness.setBrightness(viewModel.brightness),
92 - child: ScrollableWithBottomSection(
87 + return ScrollableWithBottomSection(
88 contentPadding: EdgeInsets.all(24),
89 content: Column(
90 children: [
@@ -168,7 +163,7 @@ class IoniaGiftCardDetailPage extends BasePage {
163 },
164 ),
165 ),
171 - ));
166 + );
167 }
168
169 Widget buildIoniaTile(BuildContext context, {required String title, required String subTitle}) {
lib/src/screens/new_wallet/new_wallet_page.dart
+8
@@ -38,6 +38,14 @@ class NewWalletPage extends BasePage {
38 @override
39 String get title => S.current.new_wallet;
40
41 + @override
42 + Function(BuildContext)? get pushToNextWidget => (context) {
43 + FocusScopeNode currentFocus = FocusScope.of(context);
44 + if (!currentFocus.hasPrimaryFocus) {
45 + currentFocus.focusedChild?.unfocus();
46 + }
47 + };
48 +
49 @override
50 Widget body(BuildContext context) => WalletNameForm(
51 _walletNewVM,
lib/src/screens/new_wallet/new_wallet_type_page.dart
+8
@@ -34,6 +34,14 @@ class NewWalletTypePage extends BasePage {
34 String get title =>
35 isCreate ? S.current.wallet_list_create_new_wallet : S.current.wallet_list_restore_wallet;
36
37 + @override
38 + Function(BuildContext)? get pushToNextWidget => (context) {
39 + FocusScopeNode currentFocus = FocusScope.of(context);
40 + if (!currentFocus.hasPrimaryFocus) {
41 + currentFocus.focusedChild?.unfocus();
42 + }
43 + };
44 +
45 @override
46 Widget body(BuildContext context) => WalletTypeForm(
47 onTypeSelected: onTypeSelected,
lib/src/screens/restore/restore_from_backup_page.dart
+8
@@ -21,6 +21,14 @@ class RestoreFromBackupPage extends BasePage {
21 @override
22 String get title => S.current.restore_title_from_backup;
23
24 + @override
25 + Function(BuildContext)? get pushToNextWidget => (context) {
26 + FocusScopeNode currentFocus = FocusScope.of(context);
27 + if (!currentFocus.hasPrimaryFocus) {
28 + currentFocus.focusedChild?.unfocus();
29 + }
30 + };
31 +
32 @override
33 Widget body(BuildContext context) {
34 reaction((_) => restoreFromBackupViewModel.state, (ExecutionState state) {
lib/src/screens/restore/wallet_restore_page.dart
+8
@@ -101,6 +101,14 @@ class WalletRestorePage extends BasePage {
101 // String? derivationPath = null;
102 DerivationInfo? derivationInfo;
103
104 + @override
105 + Function(BuildContext)? get pushToNextWidget => (context) {
106 + FocusScopeNode currentFocus = FocusScope.of(context);
107 + if (!currentFocus.hasPrimaryFocus) {
108 + currentFocus.focusedChild?.unfocus();
109 + }
110 + };
111 +
112 @override
113 Widget body(BuildContext context) {
114 reaction((_) => walletRestoreViewModel.state, (ExecutionState state) {
lib/src/screens/send/send_page.dart
+8
@@ -66,6 +66,14 @@ class SendPage extends BasePage {
66 @override
67 bool get extendBodyBehindAppBar => true;
68
69 + @override
70 + Function(BuildContext)? get pushToNextWidget => (context) {
71 + FocusScopeNode currentFocus = FocusScope.of(context);
72 + if (!currentFocus.hasPrimaryFocus) {
73 + currentFocus.focusedChild?.unfocus();
74 + }
75 + };
76 +
77 @override
78 Widget? leading(BuildContext context) {
79 final _backButton = Icon(
lib/src/screens/send/send_template_page.dart
+8
@@ -32,6 +32,14 @@ class SendTemplatePage extends BasePage {
32 @override
33 AppBarStyle get appBarStyle => AppBarStyle.transparent;
34
35 + @override
36 + Function(BuildContext)? get pushToNextWidget => (context) {
37 + FocusScopeNode currentFocus = FocusScope.of(context);
38 + if (!currentFocus.hasPrimaryFocus) {
39 + currentFocus.focusedChild?.unfocus();
40 + }
41 + };
42 +
43 @override
44 Widget trailing(context) => Observer(builder: (_) {
45 return sendTemplateViewModel.recipients.length > 1
lib/utils/route_aware.dart
+8 -8
@@ -10,10 +10,10 @@ class RouteAwareWidget extends StatefulWidget {
10 this.popNextWidget});
11
12 final Widget child;
13 - final Function()? pushToWidget;
14 - final Function()? pushToNextWidget;
15 - final Function()? popWidget;
16 - final Function()? popNextWidget;
13 + final Function(BuildContext context)? pushToWidget;
14 + final Function(BuildContext context)? pushToNextWidget;
15 + final Function(BuildContext context)? popWidget;
16 + final Function(BuildContext context)? popNextWidget;
17
18 @override
19 State<RouteAwareWidget> createState() => RouteAwareWidgetState();
@@ -35,28 +35,28 @@ class RouteAwareWidgetState extends State<RouteAwareWidget> with RouteAware {
35 @override
36 void didPush() {
37 if (widget.pushToWidget != null) {
38 - widget.pushToWidget!();
38 + widget.pushToWidget!(context);
39 }
40 }
41
42 @override
43 void didPushNext() {
44 if (widget.pushToNextWidget != null) {
45 - widget.pushToNextWidget!();
45 + widget.pushToNextWidget!(context);
46 }
47 }
48
49 @override
50 void didPop() {
51 if (widget.popWidget != null) {
52 - widget.popWidget!();
52 + widget.popWidget!(context);
53 }
54 }
55
56 @override
57 void didPopNext() {
58 if (widget.popNextWidget != null) {
59 - widget.popNextWidget!();
59 + widget.popNextWidget!(context);
60 }
61 }
62