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
This commit is contained in:
Omar Hatem 2022-10-26 20:13:44 +02:00 committed by GitHub
parent 4f2cf983de
commit 33935c9b1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 123 additions and 117 deletions

View file

@ -1,5 +1,5 @@
import 'package:another_flushbar/flushbar.dart';
import 'package:cake_wallet/utils/show_bar.dart'; import 'package:cake_wallet/utils/show_bar.dart';
// import 'package:flushbar/flushbar.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@ -31,9 +31,8 @@ class AuthPageState extends State<AuthPage> {
final _backArrowImageDarkTheme = final _backArrowImageDarkTheme =
Image.asset('assets/images/close_button.png'); Image.asset('assets/images/close_button.png');
ReactionDisposer? _reaction; ReactionDisposer? _reaction;
// FIX-ME: replace Flushbar Flushbar<void>? _authBar;
// Flushbar<void>? _authBar; Flushbar<void>? _progressBar;
// Flushbar<void>? _progressBar;
@override @override
void initState() { void initState() {
@ -48,39 +47,34 @@ class AuthPageState extends State<AuthPage> {
if (state is IsExecutingState) { if (state is IsExecutingState) {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
// FIX-ME: Changes related to flutter upgreade. // null duration to make it indefinite until its disposed
// Could be incorrect value for duration of auth bar _authBar =
// _authBar = createBar<void>(S.of(context).authentication, duration: null)
// createBar<void>(S.of(context).authentication, duration: Duration()) ..show(context);
// ..show(context);
}); });
} }
if (state is FailureState) { if (state is FailureState) {
print('X'); print('X');
print(state.error); print(state.error);
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) async {
_pinCodeKey.currentState?.clear(); _pinCodeKey.currentState?.clear();
// _authBar?.dismiss(); dismissFlushBar(_authBar);
showBar<void>( showBar<void>(
context, S.of(context).failed_authentication(state.error)); context, S.of(context).failed_authentication(state.error));
if (widget.onAuthenticationFinished != null) { widget.onAuthenticationFinished(false, this);
widget.onAuthenticationFinished(false, this);
}
}); });
} }
if (state is AuthenticationBanned) { if (state is AuthenticationBanned) {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) async {
_pinCodeKey.currentState?.clear(); _pinCodeKey.currentState?.clear();
// _authBar?.dismiss(); dismissFlushBar(_authBar);
showBar<void>( showBar<void>(
context, S.of(context).failed_authentication(state.error)); 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<AuthPage> {
} }
void changeProcessText(String text) { void changeProcessText(String text) {
// _authBar?.dismiss(); dismissFlushBar(_authBar);
// FIX-ME: Changes related to flutter upgreade. _progressBar = createBar<void>(text, duration: null)
// Could be incorrect value for duration of auth bar ..show(_key.currentContext!);
// _progressBar = createBar<void>(text, duration: Duration())
// ..show(_key.currentContext);
} }
void hideProgressText() { void hideProgressText() {
// _progressBar?.dismiss(); dismissFlushBar(_progressBar);
// _progressBar = null; _progressBar = null;
} }
void close() { Future<void> close({String? route}) async {
if (_key.currentContext == null) { if (_key.currentContext == null) {
throw Exception('Key context is null. Should be not happened'); throw Exception('Key context is null. Should be not happened');
} }
// _authBar?.dismiss(); WidgetsBinding.instance.addPostFrameCallback((_) async {
// _progressBar?.dismiss(); await _authBar?.dismiss();
Navigator.of(_key.currentContext!).pop(); await _progressBar?.dismiss();
if (route != null) {
Navigator.of(_key.currentContext!).pushReplacementNamed(route);
} else {
Navigator.of(_key.currentContext!).pop();
}
});
} }
@override @override
@ -147,4 +146,10 @@ class AuthPageState extends State<AuthPage> {
body: PinCode((pin, _) => widget.authViewModel.auth(password: pin), body: PinCode((pin, _) => widget.authViewModel.auth(password: pin),
(_) => null, widget.authViewModel.pinLength, false, _pinCodeKey)); (_) => null, widget.authViewModel.pinLength, false, _pinCodeKey));
} }
void dismissFlushBar(Flushbar<dynamic>? bar) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
await bar?.dismiss();
});
}
} }

View file

@ -42,8 +42,7 @@ class WalletMenu {
Navigator.of(context).pushNamed(Routes.auth, Navigator.of(context).pushNamed(Routes.auth,
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) { arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) {
if (isAuthenticatedSuccessfully) { if (isAuthenticatedSuccessfully) {
auth.close(); auth.close(route: Routes.showKeys);
Navigator.of(auth.context).pushNamed(Routes.showKeys);
} }
}); });
}), }),

View file

@ -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:cw_core/wallet_type.dart';
import 'package:cake_wallet/themes/theme_base.dart'; import 'package:cake_wallet/themes/theme_base.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart'; import 'package:cake_wallet/src/widgets/primary_button.dart';
@ -67,8 +58,6 @@ class WalletTypeFormState extends State<WalletTypeForm> {
WalletType? selected; WalletType? selected;
List<WalletType> types; List<WalletType> types;
// FIX-ME: Replace Flushbar
// Flushbar<void>? _progressBar;
@override @override
void initState() { void initState() {
@ -97,7 +86,7 @@ class WalletTypeFormState extends State<WalletTypeForm> {
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: Theme.of(context).primaryTextTheme!.headline6!.color!), color: Theme.of(context).primaryTextTheme.headline6!.color!),
), ),
), ),
...types.map((type) => Padding( ...types.map((type) => Padding(
@ -114,7 +103,7 @@ class WalletTypeFormState extends State<WalletTypeForm> {
bottomSection: PrimaryButton( bottomSection: PrimaryButton(
onPressed: () => onTypeSelected(), onPressed: () => onTypeSelected(),
text: S.of(context).seed_language_next, text: S.of(context).seed_language_next,
color: Theme.of(context).accentTextTheme!.bodyText1!.color!, color: Theme.of(context).accentTextTheme.bodyText1!.color!,
textColor: Colors.white, textColor: Colors.white,
isDisabled: selected == null, isDisabled: selected == null,
), ),

View file

@ -1,7 +1,6 @@
import 'package:cake_wallet/utils/show_bar.dart'; 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/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
class PinCodeWidget extends StatefulWidget { class PinCodeWidget extends StatefulWidget {
@ -40,8 +39,7 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
String pin; String pin;
String title; String title;
double _aspectRatio; double _aspectRatio;
// FIX-ME: Replace Flushbar Flushbar<void>? _progressBar;
// Flushbar<void>? _progressBar;
int currentPinLength() => pin.length; int currentPinLength() => pin.length;
@ -91,19 +89,18 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
void changeProcessText(String text) { void changeProcessText(String text) {
hideProgressText(); hideProgressText();
// FIX-ME: Empty Duration, _progressBar = createBar<void>(text, duration: null)
// _progressBar = createBar<void>(text, duration: Duration()) ..show(_key.currentContext!);
// ..show(_key.currentContext);
} }
void close() { void close() {
// _progressBar?.dismiss(); _progressBar?.dismiss();
Navigator.of(_key.currentContext!).pop(); Navigator.of(_key.currentContext!).pop();
} }
void hideProgressText() { void hideProgressText() {
// _progressBar?.dismiss(); _progressBar?.dismiss();
// _progressBar = null; _progressBar = null;
} }
@override @override

View file

@ -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_bar.dart';
import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.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/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_mobx/flutter_mobx.dart';
@ -49,7 +49,7 @@ class WalletListBodyState extends State<WalletListBody> {
Image.asset('assets/images/haven_logo.png', height: 24, width: 24); Image.asset('assets/images/haven_logo.png', height: 24, width: 24);
final scrollController = ScrollController(); final scrollController = ScrollController();
final double tileHeight = 60; final double tileHeight = 60;
// Flushbar<void>? _progressBar; Flushbar<void>? _progressBar;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -232,7 +232,9 @@ class WalletListBodyState extends State<WalletListBody> {
await widget.walletListViewModel.loadWallet(wallet); await widget.walletListViewModel.loadWallet(wallet);
auth.hideProgressText(); auth.hideProgressText();
auth.close(); auth.close();
Navigator.of(context).pop(); WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.of(context).pop();
});
} catch (e) { } catch (e) {
auth.changeProcessText(S auth.changeProcessText(S
.of(context) .of(context)
@ -283,13 +285,12 @@ class WalletListBodyState extends State<WalletListBody> {
} }
void changeProcessText(String text) { void changeProcessText(String text) {
// FIX-ME: Duration _progressBar = createBar<void>(text, duration: null)..show(context);
// _progressBar = createBar<void>(text, duration: Duration())..show(context);
} }
void hideProgressText() { void hideProgressText() {
// _progressBar?.dismiss(); _progressBar?.dismiss();
// _progressBar = null; _progressBar = null;
} }
ActionPane _actionPane(WalletListItem wallet) => ActionPane( ActionPane _actionPane(WalletListItem wallet) => ActionPane(

View file

@ -1,58 +1,71 @@
// import 'package:flushbar/flushbar.dart'; import 'package:another_flushbar/flushbar.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
Future<T?> showBar<T>(BuildContext context, String messageText, Future<T?> showBar<T>(BuildContext context, String messageText,
{bool isDark = false, {bool isDark = false,
Duration duration = const Duration(seconds: 1), Duration? duration = const Duration(seconds: 1), // pass explicitly by null to make the duration indefinite
bool isDismissible = true, bool isDismissible = true,
String? titleText}) async { String? titleText}) async {
// FIX-ME: Unimplemented Flushbar final bar = Flushbar<T>(
// final bar = Flushbar<T>( boxShadows: [
// boxShadows: [ BoxShadow(
// BoxShadow( color: Colors.black.withOpacity(0.09),
// color: Colors.black.withOpacity(0.09), blurRadius: 8,
// blurRadius: 8, offset: Offset(0, 2),
// offset: Offset(0, 2)) )
// ], ],
// backgroundColor: isDark ? Colors.black : Colors.white, backgroundColor: isDark ? Colors.black : Colors.white,
// borderRadius: 35, borderRadius: BorderRadius.circular(35),
// margin: EdgeInsets.all(50), margin: EdgeInsets.all(50),
// titleText: titleText != null titleText: titleText != null
// ? Text(titleText, ? Text(
// textAlign: TextAlign.center, titleText,
// style: TextStyle(color: isDark ? Colors.white : Colors.black, fontWeight: FontWeight.bold, fontSize: 24.0)) textAlign: TextAlign.center,
// : null, style: TextStyle(
// messageText: Text(messageText, color: isDark ? Colors.white : Colors.black,
// textAlign: TextAlign.center, fontWeight: FontWeight.bold,
// style: TextStyle(color: isDark ? Colors.white : Colors.black, fontSize: 16)), fontSize: 24.0,
// duration: duration, ),
// isDismissible: isDismissible, )
// flushbarPosition: FlushbarPosition.TOP, : null,
// flushbarStyle: FlushbarStyle.FLOATING); 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 bar.show(context);
return null;
} }
// FIX-ME: Unimplemented Flushbar Flushbar<T> createBar<T>(String text,
// Flushbar<T> createBar<T>(String text, {bool isDark = false,
// {bool isDark = false, Duration duration = const Duration(seconds: 1), bool isDismissible = true}) { Duration? duration = const Duration(seconds: 1), // pass explicitly by null to make the duration indefinite
// return Flushbar<T>( bool isDismissible = true}) {
// boxShadows: [ return Flushbar<T>(
// BoxShadow( boxShadows: [
// color: Colors.black.withOpacity(0.09), BoxShadow(
// blurRadius: 8, color: Colors.black.withOpacity(0.09),
// offset: Offset(0, 2)) blurRadius: 8,
// ], offset: Offset(0, 2),
// backgroundColor: isDark ? Colors.black : Colors.white, )
// borderRadius: 35, ],
// margin: EdgeInsets.all(50), backgroundColor: isDark ? Colors.black : Colors.white,
// messageText: Text(text, borderRadius: BorderRadius.circular(35),
// textAlign: TextAlign.center, margin: EdgeInsets.all(50),
// style: TextStyle(color: isDark ? Colors.white : Colors.black)), messageText: Text(text,
// duration: duration, textAlign: TextAlign.center,
// isDismissible: isDismissible, style: TextStyle(color: isDark ? Colors.white : Colors.black)),
// flushbarPosition: FlushbarPosition.TOP, duration: duration,
// flushbarStyle: FlushbarStyle.FLOATING); isDismissible: isDismissible,
// } flushbarPosition: FlushbarPosition.TOP,
flushbarStyle: FlushbarStyle.FLOATING,
);
}

View file

@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:cake_wallet/view_model/auth_state.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); final isSuccessfulAuthenticated = await _authService.authenticate(password);
if (isSuccessfulAuthenticated) { if (isSuccessfulAuthenticated) {
state = ExecutedSuccessfullyState(); WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
_failureCounter = 0; state = ExecutedSuccessfullyState();
_failureCounter = 0;
});
} else { } else {
_failureCounter += 1; _failureCounter += 1;

View file

@ -52,8 +52,7 @@ dependencies:
connectivity: ^3.0.3 connectivity: ^3.0.3
# connectivity_plus: ^2.3.5 # connectivity_plus: ^2.3.5
keyboard_actions: ^4.0.1 keyboard_actions: ^4.0.1
flushbar: ^1.10.4 another_flushbar: ^1.12.29
# check flushbar for replace
archive: ^3.3.0 archive: ^3.3.0
cryptography: ^2.0.5 cryptography: ^2.0.5
file_picker: ^4.6.1 file_picker: ^4.6.1