diff --git a/lib/src/screens/auth/auth_page.dart b/lib/src/screens/auth/auth_page.dart index 2cd4b4d66..db5e3cd4a 100644 --- a/lib/src/screens/auth/auth_page.dart +++ b/lib/src/screens/auth/auth_page.dart @@ -1,5 +1,5 @@ +import 'package:another_flushbar/flushbar.dart'; import 'package:cake_wallet/utils/show_bar.dart'; -// import 'package:flushbar/flushbar.dart'; import 'package:mobx/mobx.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; @@ -31,9 +31,8 @@ class AuthPageState extends State { final _backArrowImageDarkTheme = Image.asset('assets/images/close_button.png'); ReactionDisposer? _reaction; - // FIX-ME: replace Flushbar - // Flushbar? _authBar; - // Flushbar? _progressBar; + Flushbar? _authBar; + Flushbar? _progressBar; @override void initState() { @@ -48,39 +47,34 @@ class AuthPageState extends State { if (state is IsExecutingState) { WidgetsBinding.instance.addPostFrameCallback((_) { - // FIX-ME: Changes related to flutter upgreade. - // Could be incorrect value for duration of auth bar - // _authBar = - // createBar(S.of(context).authentication, duration: Duration()) - // ..show(context); + // null duration to make it indefinite until its disposed + _authBar = + createBar(S.of(context).authentication, duration: null) + ..show(context); }); } if (state is FailureState) { print('X'); print(state.error); - WidgetsBinding.instance.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) async { _pinCodeKey.currentState?.clear(); - // _authBar?.dismiss(); + dismissFlushBar(_authBar); showBar( context, S.of(context).failed_authentication(state.error)); - if (widget.onAuthenticationFinished != null) { - widget.onAuthenticationFinished(false, this); - } + widget.onAuthenticationFinished(false, this); }); } if (state is AuthenticationBanned) { - WidgetsBinding.instance.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) async { _pinCodeKey.currentState?.clear(); - // _authBar?.dismiss(); + dismissFlushBar(_authBar); showBar( context, S.of(context).failed_authentication(state.error)); - if (widget.onAuthenticationFinished != null) { - widget.onAuthenticationFinished(false, this); - } + widget.onAuthenticationFinished(false, this); }); } }); @@ -102,26 +96,31 @@ class AuthPageState extends State { } void changeProcessText(String text) { - // _authBar?.dismiss(); - // FIX-ME: Changes related to flutter upgreade. - // Could be incorrect value for duration of auth bar - // _progressBar = createBar(text, duration: Duration()) - // ..show(_key.currentContext); + dismissFlushBar(_authBar); + _progressBar = createBar(text, duration: null) + ..show(_key.currentContext!); } void hideProgressText() { - // _progressBar?.dismiss(); - // _progressBar = null; + dismissFlushBar(_progressBar); + _progressBar = null; } - void close() { + Future close({String? route}) async { if (_key.currentContext == null) { throw Exception('Key context is null. Should be not happened'); } - // _authBar?.dismiss(); - // _progressBar?.dismiss(); - Navigator.of(_key.currentContext!).pop(); + WidgetsBinding.instance.addPostFrameCallback((_) async { + await _authBar?.dismiss(); + await _progressBar?.dismiss(); + + if (route != null) { + Navigator.of(_key.currentContext!).pushReplacementNamed(route); + } else { + Navigator.of(_key.currentContext!).pop(); + } + }); } @override @@ -147,4 +146,10 @@ class AuthPageState extends State { body: PinCode((pin, _) => widget.authViewModel.auth(password: pin), (_) => null, widget.authViewModel.pinLength, false, _pinCodeKey)); } + + void dismissFlushBar(Flushbar? bar) { + WidgetsBinding.instance.addPostFrameCallback((_) async { + await bar?.dismiss(); + }); + } } diff --git a/lib/src/screens/dashboard/wallet_menu.dart b/lib/src/screens/dashboard/wallet_menu.dart index b7d12a190..c313eac8f 100644 --- a/lib/src/screens/dashboard/wallet_menu.dart +++ b/lib/src/screens/dashboard/wallet_menu.dart @@ -42,8 +42,7 @@ class WalletMenu { Navigator.of(context).pushNamed(Routes.auth, arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) { if (isAuthenticatedSuccessfully) { - auth.close(); - Navigator.of(auth.context).pushNamed(Routes.showKeys); + auth.close(route: Routes.showKeys); } }); }), 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 23da7320a..41179f34c 100644 --- a/lib/src/screens/new_wallet/new_wallet_type_page.dart +++ b/lib/src/screens/new_wallet/new_wallet_type_page.dart @@ -1,15 +1,6 @@ -import 'package:cake_wallet/core/execution_state.dart'; -import 'package:cake_wallet/di.dart'; -import 'package:cw_core/wallet_type.dart'; -import 'package:cake_wallet/routes.dart'; -import 'package:cake_wallet/store/settings_store.dart'; -import 'package:cake_wallet/utils/show_bar.dart'; -import 'package:cake_wallet/view_model/wallet_new_vm.dart'; -// import 'package:flushbar/flushbar.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:cake_wallet/themes/theme_base.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/cupertino.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/widgets/primary_button.dart'; @@ -67,8 +58,6 @@ class WalletTypeFormState extends State { WalletType? selected; List types; - // FIX-ME: Replace Flushbar - // Flushbar? _progressBar; @override void initState() { @@ -97,7 +86,7 @@ class WalletTypeFormState extends State { style: TextStyle( fontSize: 16, fontWeight: FontWeight.w500, - color: Theme.of(context).primaryTextTheme!.headline6!.color!), + color: Theme.of(context).primaryTextTheme.headline6!.color!), ), ), ...types.map((type) => Padding( @@ -114,7 +103,7 @@ class WalletTypeFormState extends State { bottomSection: PrimaryButton( onPressed: () => onTypeSelected(), text: S.of(context).seed_language_next, - color: Theme.of(context).accentTextTheme!.bodyText1!.color!, + color: Theme.of(context).accentTextTheme.bodyText1!.color!, textColor: Colors.white, isDisabled: selected == null, ), diff --git a/lib/src/screens/pin_code/pin_code_widget.dart b/lib/src/screens/pin_code/pin_code_widget.dart index dd763696b..a647f3d95 100644 --- a/lib/src/screens/pin_code/pin_code_widget.dart +++ b/lib/src/screens/pin_code/pin_code_widget.dart @@ -1,7 +1,6 @@ import 'package:cake_wallet/utils/show_bar.dart'; -// import 'package:flushbar/flushbar.dart'; +import 'package:another_flushbar/flushbar.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/cupertino.dart'; import 'package:cake_wallet/generated/i18n.dart'; class PinCodeWidget extends StatefulWidget { @@ -40,8 +39,7 @@ class PinCodeState extends State { String pin; String title; double _aspectRatio; - // FIX-ME: Replace Flushbar - // Flushbar? _progressBar; + Flushbar? _progressBar; int currentPinLength() => pin.length; @@ -91,19 +89,18 @@ class PinCodeState extends State { void changeProcessText(String text) { hideProgressText(); - // FIX-ME: Empty Duration, - // _progressBar = createBar(text, duration: Duration()) - // ..show(_key.currentContext); + _progressBar = createBar(text, duration: null) + ..show(_key.currentContext!); } void close() { - // _progressBar?.dismiss(); + _progressBar?.dismiss(); Navigator.of(_key.currentContext!).pop(); } void hideProgressText() { - // _progressBar?.dismiss(); - // _progressBar = null; + _progressBar?.dismiss(); + _progressBar = null; } @override diff --git a/lib/src/screens/wallet_list/wallet_list_page.dart b/lib/src/screens/wallet_list/wallet_list_page.dart index 8c0f99e67..c1a7ea953 100644 --- a/lib/src/screens/wallet_list/wallet_list_page.dart +++ b/lib/src/screens/wallet_list/wallet_list_page.dart @@ -3,7 +3,7 @@ import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/utils/show_bar.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart'; -// import 'package:flushbar/flushbar.dart'; +import 'package:another_flushbar/flushbar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; @@ -49,7 +49,7 @@ class WalletListBodyState extends State { Image.asset('assets/images/haven_logo.png', height: 24, width: 24); final scrollController = ScrollController(); final double tileHeight = 60; - // Flushbar? _progressBar; + Flushbar? _progressBar; @override Widget build(BuildContext context) { @@ -232,7 +232,9 @@ class WalletListBodyState extends State { await widget.walletListViewModel.loadWallet(wallet); auth.hideProgressText(); auth.close(); - Navigator.of(context).pop(); + WidgetsBinding.instance.addPostFrameCallback((_) { + Navigator.of(context).pop(); + }); } catch (e) { auth.changeProcessText(S .of(context) @@ -283,13 +285,12 @@ class WalletListBodyState extends State { } void changeProcessText(String text) { - // FIX-ME: Duration - // _progressBar = createBar(text, duration: Duration())..show(context); + _progressBar = createBar(text, duration: null)..show(context); } void hideProgressText() { - // _progressBar?.dismiss(); - // _progressBar = null; + _progressBar?.dismiss(); + _progressBar = null; } ActionPane _actionPane(WalletListItem wallet) => ActionPane( diff --git a/lib/utils/show_bar.dart b/lib/utils/show_bar.dart index 451887970..1480b58ac 100644 --- a/lib/utils/show_bar.dart +++ b/lib/utils/show_bar.dart @@ -1,58 +1,71 @@ -// import 'package:flushbar/flushbar.dart'; -import 'package:flutter/cupertino.dart'; +import 'package:another_flushbar/flushbar.dart'; import 'package:flutter/material.dart'; Future showBar(BuildContext context, String messageText, {bool isDark = false, - Duration duration = const Duration(seconds: 1), - bool isDismissible = true, - String? titleText}) async { - // FIX-ME: Unimplemented Flushbar - // final bar = Flushbar( - // boxShadows: [ - // BoxShadow( - // color: Colors.black.withOpacity(0.09), - // blurRadius: 8, - // offset: Offset(0, 2)) - // ], - // backgroundColor: isDark ? Colors.black : Colors.white, - // borderRadius: 35, - // margin: EdgeInsets.all(50), - // titleText: titleText != null - // ? Text(titleText, - // textAlign: TextAlign.center, - // style: TextStyle(color: isDark ? Colors.white : Colors.black, fontWeight: FontWeight.bold, fontSize: 24.0)) - // : null, - // messageText: Text(messageText, - // textAlign: TextAlign.center, - // style: TextStyle(color: isDark ? Colors.white : Colors.black, fontSize: 16)), - // duration: duration, - // isDismissible: isDismissible, - // flushbarPosition: FlushbarPosition.TOP, - // flushbarStyle: FlushbarStyle.FLOATING); + Duration? duration = const Duration(seconds: 1), // pass explicitly by null to make the duration indefinite + bool isDismissible = true, + String? titleText}) async { + final bar = Flushbar( + boxShadows: [ + BoxShadow( + color: Colors.black.withOpacity(0.09), + blurRadius: 8, + offset: Offset(0, 2), + ) + ], + backgroundColor: isDark ? Colors.black : Colors.white, + borderRadius: BorderRadius.circular(35), + margin: EdgeInsets.all(50), + titleText: titleText != null + ? Text( + titleText, + textAlign: TextAlign.center, + style: TextStyle( + color: isDark ? Colors.white : Colors.black, + fontWeight: FontWeight.bold, + fontSize: 24.0, + ), + ) + : null, + messageText: Text( + messageText, + textAlign: TextAlign.center, + style: TextStyle( + color: isDark ? Colors.white : Colors.black, + fontSize: 16, + ), + ), + duration: duration, + isDismissible: isDismissible, + flushbarPosition: FlushbarPosition.TOP, + flushbarStyle: FlushbarStyle.FLOATING, + ); - // return bar.show(context); - return null; + return bar.show(context); } -// FIX-ME: Unimplemented Flushbar -// Flushbar createBar(String text, - // {bool isDark = false, Duration duration = const Duration(seconds: 1), bool isDismissible = true}) { - // return Flushbar( - // boxShadows: [ - // BoxShadow( - // color: Colors.black.withOpacity(0.09), - // blurRadius: 8, - // offset: Offset(0, 2)) - // ], - // backgroundColor: isDark ? Colors.black : Colors.white, - // borderRadius: 35, - // margin: EdgeInsets.all(50), - // messageText: Text(text, - // textAlign: TextAlign.center, - // style: TextStyle(color: isDark ? Colors.white : Colors.black)), - // duration: duration, - // isDismissible: isDismissible, - // flushbarPosition: FlushbarPosition.TOP, - // flushbarStyle: FlushbarStyle.FLOATING); -// } +Flushbar createBar(String text, + {bool isDark = false, + Duration? duration = const Duration(seconds: 1), // pass explicitly by null to make the duration indefinite + bool isDismissible = true}) { + return Flushbar( + boxShadows: [ + BoxShadow( + color: Colors.black.withOpacity(0.09), + blurRadius: 8, + offset: Offset(0, 2), + ) + ], + backgroundColor: isDark ? Colors.black : Colors.white, + borderRadius: BorderRadius.circular(35), + margin: EdgeInsets.all(50), + messageText: Text(text, + textAlign: TextAlign.center, + style: TextStyle(color: isDark ? Colors.white : Colors.black)), + duration: duration, + isDismissible: isDismissible, + flushbarPosition: FlushbarPosition.TOP, + flushbarStyle: FlushbarStyle.FLOATING, + ); +} diff --git a/lib/view_model/auth_view_model.dart b/lib/view_model/auth_view_model.dart index 0003b0275..29ef46b47 100644 --- a/lib/view_model/auth_view_model.dart +++ b/lib/view_model/auth_view_model.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/view_model/auth_state.dart'; @@ -55,8 +56,10 @@ abstract class AuthViewModelBase with Store { final isSuccessfulAuthenticated = await _authService.authenticate(password); if (isSuccessfulAuthenticated) { - state = ExecutedSuccessfullyState(); - _failureCounter = 0; + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + state = ExecutedSuccessfullyState(); + _failureCounter = 0; + }); } else { _failureCounter += 1; diff --git a/pubspec_base.yaml b/pubspec_base.yaml index 2a6ebfb55..7a3abd3bc 100644 --- a/pubspec_base.yaml +++ b/pubspec_base.yaml @@ -52,8 +52,7 @@ dependencies: connectivity: ^3.0.3 # connectivity_plus: ^2.3.5 keyboard_actions: ^4.0.1 - flushbar: ^1.10.4 - # check flushbar for replace + another_flushbar: ^1.12.29 archive: ^3.3.0 cryptography: ^2.0.5 file_picker: ^4.6.1