mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
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:
parent
4f2cf983de
commit
33935c9b1d
8 changed files with 123 additions and 117 deletions
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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<T?> showBar<T>(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<T>(
|
||||
// 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<T>(
|
||||
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<T> createBar<T>(String text,
|
||||
// {bool isDark = false, Duration duration = const Duration(seconds: 1), bool isDismissible = true}) {
|
||||
// return Flushbar<T>(
|
||||
// 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<T> createBar<T>(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<T>(
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue