Fix authentication required when minimize app

This commit is contained in:
Godwin Asuquo 2022-11-30 22:57:48 +02:00
parent 7da2de60cb
commit 34cfe7591f

View file

@ -1,4 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:cake_wallet/core/auth_service.dart';
import 'package:cake_wallet/di.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/auth/auth_page.dart'; import 'package:cake_wallet/src/screens/auth/auth_page.dart';
@ -28,15 +30,18 @@ class RootState extends State<Root> with WidgetsBindingObserver {
RootState() RootState()
: _isInactiveController = StreamController<bool>.broadcast(), : _isInactiveController = StreamController<bool>.broadcast(),
_isInactive = false, _isInactive = false,
_requestAuth = getIt.get<AuthService>().requireAuth(),
_postFrameCallback = false; _postFrameCallback = false;
Stream<bool> get isInactive => _isInactiveController.stream; Stream<bool> get isInactive => _isInactiveController.stream;
StreamController<bool> _isInactiveController; StreamController<bool> _isInactiveController;
bool _isInactive; bool _isInactive;
bool _postFrameCallback; bool _postFrameCallback;
bool _requestAuth;
@override @override
void initState() { void initState() {
_isInactiveController = StreamController<bool>.broadcast(); _isInactiveController = StreamController<bool>.broadcast();
_isInactive = false; _isInactive = false;
_postFrameCallback = false; _postFrameCallback = false;
@ -52,6 +57,10 @@ class RootState extends State<Root> with WidgetsBindingObserver {
return; return;
} }
setState(() {
_requestAuth = getIt.get<AuthService>().requireAuth();
});
if (!_isInactive && if (!_isInactive &&
widget.authenticationStore.state == AuthenticationState.allowed) { widget.authenticationStore.state == AuthenticationState.allowed) {
setState(() => _setInactive(true)); setState(() => _setInactive(true));
@ -65,7 +74,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_isInactive && !_postFrameCallback) { if (_isInactive && !_postFrameCallback && _requestAuth) {
_postFrameCallback = true; _postFrameCallback = true;
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
widget.navigatorKey.currentState?.pushNamed(Routes.unlock, widget.navigatorKey.currentState?.pushNamed(Routes.unlock,