2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:cake_wallet/routes.dart';
|
2020-01-08 12:26:34 +00:00
|
|
|
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/store/app_store.dart';
|
|
|
|
import 'package:cake_wallet/store/authentication_store.dart';
|
|
|
|
import 'package:cake_wallet/entities/qr_scanner.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
class Root extends StatefulWidget {
|
2020-09-14 12:08:33 +00:00
|
|
|
Root({Key key, this.authenticationStore, this.appStore, this.child})
|
|
|
|
: super(key: key);
|
2020-06-20 07:10:00 +00:00
|
|
|
|
|
|
|
final AuthenticationStore authenticationStore;
|
|
|
|
final AppStore appStore;
|
2020-09-14 12:08:33 +00:00
|
|
|
final Widget child;
|
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-09-21 11:50:26 +00:00
|
|
|
if (!_isInactive &&
|
|
|
|
widget.authenticationStore.state == AuthenticationState.allowed) {
|
|
|
|
setState(() => _isInactive = true);
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-21 11:50:26 +00:00
|
|
|
if (_isInactive && !_postFrameCallback) {
|
|
|
|
_postFrameCallback = true;
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
Navigator.of(context).pushNamed(Routes.unlock,
|
|
|
|
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) {
|
|
|
|
if (!isAuthenticatedSuccessfully) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_reset();
|
|
|
|
auth.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-06-20 07:10:00 +00:00
|
|
|
|
2020-09-21 11:50:26 +00:00
|
|
|
return widget.child;
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-09-21 11:50:26 +00:00
|
|
|
void _reset() {
|
|
|
|
setState(() {
|
|
|
|
_postFrameCallback = false;
|
|
|
|
_isInactive = false;
|
|
|
|
});
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
}
|