2020-06-20 07:10:00 +00:00
|
|
|
import 'package:cake_wallet/di.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/dashboard/dashboard_page.dart';
|
|
|
|
import 'package:cake_wallet/store/app_store.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:cake_wallet/routes.dart';
|
2020-06-20 07:10:00 +00:00
|
|
|
import 'package:cake_wallet/store/authentication_store.dart';
|
|
|
|
|
|
|
|
//import 'package:cake_wallet/src/stores/authentication/authentication_store.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:cake_wallet/src/stores/price/price_store.dart';
|
|
|
|
import 'package:cake_wallet/src/stores/settings/settings_store.dart';
|
|
|
|
import 'package:cake_wallet/src/stores/wallet/wallet_store.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/common/qr_scanner.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/services/user_service.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/services/wallet_list_service.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/services/wallet_service.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/exchange/trade.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/monero/transaction_description.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/auth/create_login_page.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/dashboard/create_dashboard_page.dart';
|
2020-01-08 12:26:34 +00:00
|
|
|
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/welcome/create_welcome_page.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
class Root extends StatefulWidget {
|
2020-06-20 07:10:00 +00:00
|
|
|
Root({Key key, this.authenticationStore, this.appStore}) : super(key: key);
|
|
|
|
|
|
|
|
final AuthenticationStore authenticationStore;
|
|
|
|
final AppStore appStore;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
RootState createState() => RootState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class RootState extends State<Root> with WidgetsBindingObserver {
|
|
|
|
bool _isInactive;
|
|
|
|
bool _postFrameCallback;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_isInactive = false;
|
|
|
|
_postFrameCallback = false;
|
|
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
|
switch (state) {
|
|
|
|
case AppLifecycleState.paused:
|
|
|
|
if (isQrScannerShown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
// if (!_isInactive &&
|
|
|
|
// widget.authenticationStore.state ==
|
|
|
|
// AuthenticationState.authenticated ||
|
|
|
|
// widget.authenticationStore.state == AuthenticationState.active) {
|
|
|
|
// setState(() => _isInactive = true);
|
|
|
|
// }
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-06-20 07:10:00 +00:00
|
|
|
// _authenticationStore = Provider.of<AuthenticationStore>(context);
|
|
|
|
// final sharedPreferences = Provider.of<SharedPreferences>(context);
|
|
|
|
// final walletListService = Provider.of<WalletListService>(context);
|
|
|
|
// final walletService = Provider.of<WalletService>(context);
|
|
|
|
// final userService = Provider.of<UserService>(context);
|
|
|
|
// final priceStore = Provider.of<PriceStore>(context);
|
|
|
|
// final authenticationStore = Provider.of<AuthenticationStore>(context);
|
|
|
|
// final trades = Provider.of<Box<Trade>>(context);
|
|
|
|
// final transactionDescriptions =
|
|
|
|
// Provider.of<Box<TransactionDescription>>(context);
|
|
|
|
// final walletStore = Provider.of<WalletStore>(context);
|
|
|
|
// final settingsStore = Provider.of<SettingsStore>(context);
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
if (_isInactive && !_postFrameCallback) {
|
|
|
|
_postFrameCallback = true;
|
|
|
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
Navigator.of(context).pushNamed(Routes.unlock,
|
2020-01-08 12:26:34 +00:00
|
|
|
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) {
|
2020-01-04 19:31:52 +00:00
|
|
|
if (!isAuthenticatedSuccessfully) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_postFrameCallback = false;
|
|
|
|
_isInactive = false;
|
|
|
|
});
|
|
|
|
auth.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Observer(builder: (_) {
|
2020-06-20 07:10:00 +00:00
|
|
|
final state = widget.authenticationStore.state;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
if (state == AuthenticationState.denied) {
|
|
|
|
return createWelcomePage();
|
|
|
|
}
|
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
if (state == AuthenticationState.installed) {
|
2020-07-06 20:09:03 +00:00
|
|
|
return getIt.get<AuthPage>(instanceName: 'login');
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
if (state == AuthenticationState.allowed) {
|
|
|
|
return getIt.get<DashboardPage>();
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
// if (state == AuthenticationState.denied) {
|
|
|
|
// return createWelcomePage();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (state == AuthenticationState.readyToLogin) {
|
|
|
|
// return createLoginPage(
|
|
|
|
// sharedPreferences: sharedPreferences,
|
|
|
|
// userService: userService,
|
|
|
|
// walletService: walletService,
|
|
|
|
// walletListService: walletListService,
|
|
|
|
// authenticationStore: authenticationStore);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (state == AuthenticationState.authenticated ||
|
|
|
|
// state == AuthenticationState.restored) {
|
|
|
|
// return createDashboardPage(
|
|
|
|
// walletService: walletService,
|
|
|
|
// priceStore: priceStore,
|
|
|
|
// trades: trades,
|
|
|
|
// transactionDescriptions: transactionDescriptions,
|
|
|
|
// walletStore: walletStore,
|
|
|
|
// settingsStore: settingsStore);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (state == AuthenticationState.created) {
|
|
|
|
// return createSeedPage(
|
|
|
|
// settingsStore: settingsStore,
|
|
|
|
// walletService: walletService,
|
|
|
|
// callback: () =>
|
|
|
|
// _authenticationStore.state = AuthenticationState.authenticated);
|
|
|
|
// }
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
return Container(color: Colors.white);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|