Fix authentication required when minimize app

Godwin Asuquo committed Nov 30, 2022 at 22:57 UTC 34cfe7591f7917150c0191af92cf9412f75fe561
1 file changed +10 -1
lib/src/screens/root/root.dart
+10 -1
@@ -1,4 +1,6 @@
1 import 'dart:async';
2 +import 'package:cake_wallet/core/auth_service.dart';
3 +import 'package:cake_wallet/di.dart';
4 import 'package:flutter/material.dart';
5 import 'package:cake_wallet/routes.dart';
6 import 'package:cake_wallet/src/screens/auth/auth_page.dart';
@@ -28,15 +30,18 @@ class RootState extends State<Root> with WidgetsBindingObserver {
30 RootState()
31 : _isInactiveController = StreamController<bool>.broadcast(),
32 _isInactive = false,
33 + _requestAuth = getIt.get<AuthService>().requireAuth(),
34 _postFrameCallback = false;
35
36 Stream<bool> get isInactive => _isInactiveController.stream;
37 StreamController<bool> _isInactiveController;
38 bool _isInactive;
39 bool _postFrameCallback;
40 + bool _requestAuth;
41
42 @override
43 void initState() {
44 +
45 _isInactiveController = StreamController<bool>.broadcast();
46 _isInactive = false;
47 _postFrameCallback = false;
@@ -52,6 +57,10 @@ class RootState extends State<Root> with WidgetsBindingObserver {
57 return;
58 }
59
60 + setState(() {
61 + _requestAuth = getIt.get<AuthService>().requireAuth();
62 + });
63 +
64 if (!_isInactive &&
65 widget.authenticationStore.state == AuthenticationState.allowed) {
66 setState(() => _setInactive(true));
@@ -65,7 +74,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
74
75 @override
76 Widget build(BuildContext context) {
68 - if (_isInactive && !_postFrameCallback) {
77 + if (_isInactive && !_postFrameCallback && _requestAuth) {
78 _postFrameCallback = true;
79 WidgetsBinding.instance.addPostFrameCallback((_) {
80 widget.navigatorKey.currentState?.pushNamed(Routes.unlock,