Update flushbar (#568)
* Replace old flushbar package with its updated version Fix flushbars throughtout the app * Fix Navigation happening all at once causing debugLocked error * Remove un-necessary async/await * Remove un-necessary future delayed * Make process text flushbar indefinite * Fix show seeds/keys popping page after being pushed instead of popping the auth route
Omar Hatem committed
Oct 26, 2022 at 20:13 UTC
33935c9b1d7722fb9bf90d26873fa7bcd4fc8639
8 files changed
+123
-117
lib/src/screens/auth/auth_page.dart
+35
-30
@@ -1,5 +1,5 @@
1
+import 'package:another_flushbar/flushbar.dart';
2
import 'package:cake_wallet/utils/show_bar.dart';
2
-// import 'package:flushbar/flushbar.dart';
3
import 'package:mobx/mobx.dart';
4
import 'package:flutter/material.dart';
5
import 'package:flutter/cupertino.dart';
@@ -31,9 +31,8 @@ class AuthPageState extends State<AuthPage> {
31
final _backArrowImageDarkTheme =
32
Image.asset('assets/images/close_button.png');
33
ReactionDisposer? _reaction;
34
- // FIX-ME: replace Flushbar
35
- // Flushbar<void>? _authBar;
36
- // Flushbar<void>? _progressBar;
34
+ Flushbar<void>? _authBar;
35
+ Flushbar<void>? _progressBar;
36
37
@override
38
void initState() {
@@ -48,39 +47,34 @@ class AuthPageState extends State<AuthPage> {
47
48
if (state is IsExecutingState) {
49
WidgetsBinding.instance.addPostFrameCallback((_) {
51
- // FIX-ME: Changes related to flutter upgreade.
52
- // Could be incorrect value for duration of auth bar
53
- // _authBar =
54
- // createBar<void>(S.of(context).authentication, duration: Duration())
55
- // ..show(context);
50
+ // null duration to make it indefinite until its disposed
51
+ _authBar =
52
+ createBar<void>(S.of(context).authentication, duration: null)
53
+ ..show(context);
54
});
55
}
56
57
if (state is FailureState) {
58
print('X');
59
print(state.error);
62
- WidgetsBinding.instance.addPostFrameCallback((_) {
60
+ WidgetsBinding.instance.addPostFrameCallback((_) async {
61
_pinCodeKey.currentState?.clear();
64
- // _authBar?.dismiss();
62
+ dismissFlushBar(_authBar);
63
showBar<void>(
64
context, S.of(context).failed_authentication(state.error));
65
68
- if (widget.onAuthenticationFinished != null) {
69
- widget.onAuthenticationFinished(false, this);
70
- }
66
+ widget.onAuthenticationFinished(false, this);
67
});
68
}
69
70
if (state is AuthenticationBanned) {
75
- WidgetsBinding.instance.addPostFrameCallback((_) {
71
+ WidgetsBinding.instance.addPostFrameCallback((_) async {
72
_pinCodeKey.currentState?.clear();
77
- // _authBar?.dismiss();
73
+ dismissFlushBar(_authBar);
74
showBar<void>(
75
context, S.of(context).failed_authentication(state.error));
76
81
- if (widget.onAuthenticationFinished != null) {
82
- widget.onAuthenticationFinished(false, this);
83
- }
77
+ widget.onAuthenticationFinished(false, this);
78
});
79
}
80
});
@@ -102,26 +96,31 @@ class AuthPageState extends State<AuthPage> {
96
}
97
98
void changeProcessText(String text) {
105
- // _authBar?.dismiss();
106
- // FIX-ME: Changes related to flutter upgreade.
107
- // Could be incorrect value for duration of auth bar
108
- // _progressBar = createBar<void>(text, duration: Duration())
109
- // ..show(_key.currentContext);
99
+ dismissFlushBar(_authBar);
100
+ _progressBar = createBar<void>(text, duration: null)
101
+ ..show(_key.currentContext!);
102
}
103
104
void hideProgressText() {
113
- // _progressBar?.dismiss();
114
- // _progressBar = null;
105
+ dismissFlushBar(_progressBar);
106
+ _progressBar = null;
107
}
108
117
- void close() {
109
+ Future<void> close({String? route}) async {
110
if (_key.currentContext == null) {
111
throw Exception('Key context is null. Should be not happened');
112
}
113
122
- // _authBar?.dismiss();
123
- // _progressBar?.dismiss();
124
- Navigator.of(_key.currentContext!).pop();
114
+ WidgetsBinding.instance.addPostFrameCallback((_) async {
115
+ await _authBar?.dismiss();
116
+ await _progressBar?.dismiss();
117
+
118
+ if (route != null) {
119
+ Navigator.of(_key.currentContext!).pushReplacementNamed(route);
120
+ } else {
121
+ Navigator.of(_key.currentContext!).pop();
122
+ }
123
+ });
124
}
125
126
@override
@@ -147,4 +146,10 @@ class AuthPageState extends State<AuthPage> {
146
body: PinCode((pin, _) => widget.authViewModel.auth(password: pin),
147
(_) => null, widget.authViewModel.pinLength, false, _pinCodeKey));
148
}
149
+
150
+ void dismissFlushBar(Flushbar<dynamic>? bar) {
151
+ WidgetsBinding.instance.addPostFrameCallback((_) async {
152
+ await bar?.dismiss();
153
+ });
154
+ }
155
}
lib/src/screens/dashboard/wallet_menu.dart
+1
-2
@@ -42,8 +42,7 @@ class WalletMenu {
42
Navigator.of(context).pushNamed(Routes.auth,
43
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) {
44
if (isAuthenticatedSuccessfully) {
45
- auth.close();
46
- Navigator.of(auth.context).pushNamed(Routes.showKeys);
45
+ auth.close(route: Routes.showKeys);
46
}
47
});
48
}),
lib/src/screens/new_wallet/new_wallet_type_page.dart
+2
-13
@@ -1,15 +1,6 @@
1
-import 'package:cake_wallet/core/execution_state.dart';
2
-import 'package:cake_wallet/di.dart';
3
-import 'package:cw_core/wallet_type.dart';
4
-import 'package:cake_wallet/routes.dart';
5
-import 'package:cake_wallet/store/settings_store.dart';
6
-import 'package:cake_wallet/utils/show_bar.dart';
7
-import 'package:cake_wallet/view_model/wallet_new_vm.dart';
8
-// import 'package:flushbar/flushbar.dart';
1
import 'package:cw_core/wallet_type.dart';
2
import 'package:cake_wallet/themes/theme_base.dart';
3
import 'package:flutter/material.dart';
12
-import 'package:flutter/cupertino.dart';
4
import 'package:cake_wallet/generated/i18n.dart';
5
import 'package:cake_wallet/src/screens/base_page.dart';
6
import 'package:cake_wallet/src/widgets/primary_button.dart';
@@ -67,8 +58,6 @@ class WalletTypeFormState extends State<WalletTypeForm> {
58
59
WalletType? selected;
60
List<WalletType> types;
70
- // FIX-ME: Replace Flushbar
71
- // Flushbar<void>? _progressBar;
61
62
@override
63
void initState() {
@@ -97,7 +86,7 @@ class WalletTypeFormState extends State<WalletTypeForm> {
86
style: TextStyle(
87
fontSize: 16,
88
fontWeight: FontWeight.w500,
100
- color: Theme.of(context).primaryTextTheme!.headline6!.color!),
89
+ color: Theme.of(context).primaryTextTheme.headline6!.color!),
90
),
91
),
92
...types.map((type) => Padding(
@@ -114,7 +103,7 @@ class WalletTypeFormState extends State<WalletTypeForm> {
103
bottomSection: PrimaryButton(
104
onPressed: () => onTypeSelected(),
105
text: S.of(context).seed_language_next,
117
- color: Theme.of(context).accentTextTheme!.bodyText1!.color!,
106
+ color: Theme.of(context).accentTextTheme.bodyText1!.color!,
107
textColor: Colors.white,
108
isDisabled: selected == null,
109
),
lib/src/screens/pin_code/pin_code_widget.dart
+7
-10
@@ -1,7 +1,6 @@
1
import 'package:cake_wallet/utils/show_bar.dart';
2
-// import 'package:flushbar/flushbar.dart';
2
+import 'package:another_flushbar/flushbar.dart';
3
import 'package:flutter/material.dart';
4
-import 'package:flutter/cupertino.dart';
4
import 'package:cake_wallet/generated/i18n.dart';
5
6
class PinCodeWidget extends StatefulWidget {
@@ -40,8 +39,7 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
39
String pin;
40
String title;
41
double _aspectRatio;
43
- // FIX-ME: Replace Flushbar
44
- // Flushbar<void>? _progressBar;
42
+ Flushbar<void>? _progressBar;
43
44
int currentPinLength() => pin.length;
45
@@ -91,19 +89,18 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
89
90
void changeProcessText(String text) {
91
hideProgressText();
94
- // FIX-ME: Empty Duration,
95
- // _progressBar = createBar<void>(text, duration: Duration())
96
- // ..show(_key.currentContext);
92
+ _progressBar = createBar<void>(text, duration: null)
93
+ ..show(_key.currentContext!);
94
}
95
96
void close() {
100
- // _progressBar?.dismiss();
97
+ _progressBar?.dismiss();
98
Navigator.of(_key.currentContext!).pop();
99
}
100
101
void hideProgressText() {
105
- // _progressBar?.dismiss();
106
- // _progressBar = null;
102
+ _progressBar?.dismiss();
103
+ _progressBar = null;
104
}
105
106
@override
lib/src/screens/wallet_list/wallet_list_page.dart
+8
-7
@@ -3,7 +3,7 @@ import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
3
import 'package:cake_wallet/utils/show_bar.dart';
4
import 'package:cake_wallet/utils/show_pop_up.dart';
5
import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart';
6
-// import 'package:flushbar/flushbar.dart';
6
+import 'package:another_flushbar/flushbar.dart';
7
import 'package:flutter/material.dart';
8
import 'package:flutter/cupertino.dart';
9
import 'package:flutter_mobx/flutter_mobx.dart';
@@ -49,7 +49,7 @@ class WalletListBodyState extends State<WalletListBody> {
49
Image.asset('assets/images/haven_logo.png', height: 24, width: 24);
50
final scrollController = ScrollController();
51
final double tileHeight = 60;
52
- // Flushbar<void>? _progressBar;
52
+ Flushbar<void>? _progressBar;
53
54
@override
55
Widget build(BuildContext context) {
@@ -232,7 +232,9 @@ class WalletListBodyState extends State<WalletListBody> {
232
await widget.walletListViewModel.loadWallet(wallet);
233
auth.hideProgressText();
234
auth.close();
235
- Navigator.of(context).pop();
235
+ WidgetsBinding.instance.addPostFrameCallback((_) {
236
+ Navigator.of(context).pop();
237
+ });
238
} catch (e) {
239
auth.changeProcessText(S
240
.of(context)
@@ -283,13 +285,12 @@ class WalletListBodyState extends State<WalletListBody> {
285
}
286
287
void changeProcessText(String text) {
286
- // FIX-ME: Duration
287
- // _progressBar = createBar<void>(text, duration: Duration())..show(context);
288
+ _progressBar = createBar<void>(text, duration: null)..show(context);
289
}
290
291
void hideProgressText() {
291
- // _progressBar?.dismiss();
292
- // _progressBar = null;
292
+ _progressBar?.dismiss();
293
+ _progressBar = null;
294
}
295
296
ActionPane _actionPane(WalletListItem wallet) => ActionPane(
lib/utils/show_bar.dart
+64
-51
@@ -1,58 +1,71 @@
1
-// import 'package:flushbar/flushbar.dart';
2
-import 'package:flutter/cupertino.dart';
1
+import 'package:another_flushbar/flushbar.dart';
2
import 'package:flutter/material.dart';
3
4
Future<T?> showBar<T>(BuildContext context, String messageText,
5
{bool isDark = false,
7
- Duration duration = const Duration(seconds: 1),
8
- bool isDismissible = true,
9
- String? titleText}) async {
10
- // FIX-ME: Unimplemented Flushbar
11
- // final bar = Flushbar<T>(
12
- // boxShadows: [
13
- // BoxShadow(
14
- // color: Colors.black.withOpacity(0.09),
15
- // blurRadius: 8,
16
- // offset: Offset(0, 2))
17
- // ],
18
- // backgroundColor: isDark ? Colors.black : Colors.white,
19
- // borderRadius: 35,
20
- // margin: EdgeInsets.all(50),
21
- // titleText: titleText != null
22
- // ? Text(titleText,
23
- // textAlign: TextAlign.center,
24
- // style: TextStyle(color: isDark ? Colors.white : Colors.black, fontWeight: FontWeight.bold, fontSize: 24.0))
25
- // : null,
26
- // messageText: Text(messageText,
27
- // textAlign: TextAlign.center,
28
- // style: TextStyle(color: isDark ? Colors.white : Colors.black, fontSize: 16)),
29
- // duration: duration,
30
- // isDismissible: isDismissible,
31
- // flushbarPosition: FlushbarPosition.TOP,
32
- // flushbarStyle: FlushbarStyle.FLOATING);
6
+ Duration? duration = const Duration(seconds: 1), // pass explicitly by null to make the duration indefinite
7
+ bool isDismissible = true,
8
+ String? titleText}) async {
9
+ final bar = Flushbar<T>(
10
+ boxShadows: [
11
+ BoxShadow(
12
+ color: Colors.black.withOpacity(0.09),
13
+ blurRadius: 8,
14
+ offset: Offset(0, 2),
15
+ )
16
+ ],
17
+ backgroundColor: isDark ? Colors.black : Colors.white,
18
+ borderRadius: BorderRadius.circular(35),
19
+ margin: EdgeInsets.all(50),
20
+ titleText: titleText != null
21
+ ? Text(
22
+ titleText,
23
+ textAlign: TextAlign.center,
24
+ style: TextStyle(
25
+ color: isDark ? Colors.white : Colors.black,
26
+ fontWeight: FontWeight.bold,
27
+ fontSize: 24.0,
28
+ ),
29
+ )
30
+ : null,
31
+ messageText: Text(
32
+ messageText,
33
+ textAlign: TextAlign.center,
34
+ style: TextStyle(
35
+ color: isDark ? Colors.white : Colors.black,
36
+ fontSize: 16,
37
+ ),
38
+ ),
39
+ duration: duration,
40
+ isDismissible: isDismissible,
41
+ flushbarPosition: FlushbarPosition.TOP,
42
+ flushbarStyle: FlushbarStyle.FLOATING,
43
+ );
44
34
- // return bar.show(context);
35
- return null;
45
+ return bar.show(context);
46
}
47
38
-// FIX-ME: Unimplemented Flushbar
39
-// Flushbar<T> createBar<T>(String text,
40
- // {bool isDark = false, Duration duration = const Duration(seconds: 1), bool isDismissible = true}) {
41
- // return Flushbar<T>(
42
- // boxShadows: [
43
- // BoxShadow(
44
- // color: Colors.black.withOpacity(0.09),
45
- // blurRadius: 8,
46
- // offset: Offset(0, 2))
47
- // ],
48
- // backgroundColor: isDark ? Colors.black : Colors.white,
49
- // borderRadius: 35,
50
- // margin: EdgeInsets.all(50),
51
- // messageText: Text(text,
52
- // textAlign: TextAlign.center,
53
- // style: TextStyle(color: isDark ? Colors.white : Colors.black)),
54
- // duration: duration,
55
- // isDismissible: isDismissible,
56
- // flushbarPosition: FlushbarPosition.TOP,
57
- // flushbarStyle: FlushbarStyle.FLOATING);
58
-// }
48
+Flushbar<T> createBar<T>(String text,
49
+ {bool isDark = false,
50
+ Duration? duration = const Duration(seconds: 1), // pass explicitly by null to make the duration indefinite
51
+ bool isDismissible = true}) {
52
+ return Flushbar<T>(
53
+ boxShadows: [
54
+ BoxShadow(
55
+ color: Colors.black.withOpacity(0.09),
56
+ blurRadius: 8,
57
+ offset: Offset(0, 2),
58
+ )
59
+ ],
60
+ backgroundColor: isDark ? Colors.black : Colors.white,
61
+ borderRadius: BorderRadius.circular(35),
62
+ margin: EdgeInsets.all(50),
63
+ messageText: Text(text,
64
+ textAlign: TextAlign.center,
65
+ style: TextStyle(color: isDark ? Colors.white : Colors.black)),
66
+ duration: duration,
67
+ isDismissible: isDismissible,
68
+ flushbarPosition: FlushbarPosition.TOP,
69
+ flushbarStyle: FlushbarStyle.FLOATING,
70
+ );
71
+}
lib/view_model/auth_view_model.dart
+5
-2
@@ -1,4 +1,5 @@
1
import 'dart:async';
2
+import 'package:flutter/material.dart';
3
import 'package:shared_preferences/shared_preferences.dart';
4
import 'package:mobx/mobx.dart';
5
import 'package:cake_wallet/view_model/auth_state.dart';
@@ -55,8 +56,10 @@ abstract class AuthViewModelBase with Store {
56
final isSuccessfulAuthenticated = await _authService.authenticate(password);
57
58
if (isSuccessfulAuthenticated) {
58
- state = ExecutedSuccessfullyState();
59
- _failureCounter = 0;
59
+ WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
60
+ state = ExecutedSuccessfullyState();
61
+ _failureCounter = 0;
62
+ });
63
} else {
64
_failureCounter += 1;
65
pubspec_base.yaml
+1
-2
@@ -52,8 +52,7 @@ dependencies:
52
connectivity: ^3.0.3
53
# connectivity_plus: ^2.3.5
54
keyboard_actions: ^4.0.1
55
- flushbar: ^1.10.4
56
- # check flushbar for replace
55
+ another_flushbar: ^1.12.29
56
archive: ^3.3.0
57
cryptography: ^2.0.5
58
file_picker: ^4.6.1