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 14:13:44 -04:00
committed by GitHub
parent 4f2cf983de
commit 33935c9b1d
8 changed files with 123 additions and 117 deletions
+35 -30
View File
@@ -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<AuthPage> {
final _backArrowImageDarkTheme =
Image.asset('assets/images/close_button.png');
ReactionDisposer? _reaction;
// FIX-ME: replace Flushbar
// Flushbar<void>? _authBar;
// Flushbar<void>? _progressBar;
Flushbar<void>? _authBar;
Flushbar<void>? _progressBar;
@override
void initState() {
@@ -48,39 +47,34 @@ class AuthPageState extends State<AuthPage> {
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<void>(S.of(context).authentication, duration: Duration())
// ..show(context);
// null duration to make it indefinite until its disposed
_authBar =
createBar<void>(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<void>(
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<void>(
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) {
// _authBar?.dismiss();
// FIX-ME: Changes related to flutter upgreade.
// Could be incorrect value for duration of auth bar
// _progressBar = createBar<void>(text, duration: Duration())
// ..show(_key.currentContext);
dismissFlushBar(_authBar);
_progressBar = createBar<void>(text, duration: null)
..show(_key.currentContext!);
}
void hideProgressText() {
// _progressBar?.dismiss();
// _progressBar = null;
dismissFlushBar(_progressBar);
_progressBar = null;
}
void close() {
Future<void> 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<AuthPage> {
body: PinCode((pin, _) => widget.authViewModel.auth(password: pin),
(_) => null, widget.authViewModel.pinLength, false, _pinCodeKey));
}
void dismissFlushBar(Flushbar<dynamic>? bar) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
await bar?.dismiss();
});
}
}
+1 -2
View File
@@ -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);
}
});
}),
@@ -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<WalletTypeForm> {
WalletType? selected;
List<WalletType> types;
// FIX-ME: Replace Flushbar
// Flushbar<void>? _progressBar;
@override
void initState() {
@@ -97,7 +86,7 @@ class WalletTypeFormState extends State<WalletTypeForm> {
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<WalletTypeForm> {
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,
),
+7 -10
View File
@@ -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<T extends PinCodeWidget> extends State<T> {
String pin;
String title;
double _aspectRatio;
// FIX-ME: Replace Flushbar
// Flushbar<void>? _progressBar;
Flushbar<void>? _progressBar;
int currentPinLength() => pin.length;
@@ -91,19 +89,18 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
void changeProcessText(String text) {
hideProgressText();
// FIX-ME: Empty Duration,
// _progressBar = createBar<void>(text, duration: Duration())
// ..show(_key.currentContext);
_progressBar = createBar<void>(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
@@ -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<WalletListBody> {
Image.asset('assets/images/haven_logo.png', height: 24, width: 24);
final scrollController = ScrollController();
final double tileHeight = 60;
// Flushbar<void>? _progressBar;
Flushbar<void>? _progressBar;
@override
Widget build(BuildContext context) {
@@ -232,7 +232,9 @@ class WalletListBodyState extends State<WalletListBody> {
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<WalletListBody> {
}
void changeProcessText(String text) {
// FIX-ME: Duration
// _progressBar = createBar<void>(text, duration: Duration())..show(context);
_progressBar = createBar<void>(text, duration: null)..show(context);
}
void hideProgressText() {
// _progressBar?.dismiss();
// _progressBar = null;
_progressBar?.dismiss();
_progressBar = null;
}
ActionPane _actionPane(WalletListItem wallet) => ActionPane(