Fix two instance of lockscreen prompt (#1459)

This commit is contained in:
Neeraj Gupta 2023-11-01 08:22:05 +05:30 committed by GitHub
commit 196c987011
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,13 +17,16 @@ class _LockScreenState extends State<LockScreen> with WidgetsBindingObserver {
bool _isShowingLockScreen = false;
bool _hasPlacedAppInBackground = false;
bool _hasAuthenticationFailed = false;
int? lastAuthenticatingTime;
@override
void initState() {
_logger.info("initState");
_showLockScreen();
WidgetsBinding.instance.addObserver(this);
super.initState();
WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance!.addPostFrameCallback((_) {
_showLockScreen(source: "initState");
});
}
@override
@ -47,7 +50,7 @@ class _LockScreenState extends State<LockScreen> with WidgetsBindingObserver {
text: S.of(context).unlock,
iconData: Icons.lock_open_outlined,
onTap: () async {
_showLockScreen();
_showLockScreen(source: "tapUnlock");
},
),
),
@ -66,10 +69,13 @@ class _LockScreenState extends State<LockScreen> with WidgetsBindingObserver {
// This is triggered either when the lock screen is dismissed or when
// the app is brought to foreground
_hasPlacedAppInBackground = false;
if (!_hasAuthenticationFailed) {
final bool didAuthInLast5Seconds = lastAuthenticatingTime != null &&
DateTime.now().millisecondsSinceEpoch - lastAuthenticatingTime! <
5000;
if (!_hasAuthenticationFailed && !didAuthInLast5Seconds) {
// Show the lock screen again only if the app is resuming from the
// background, and not when the lock screen was explicitly dismissed
_showLockScreen();
_showLockScreen(source: "lifeCycle");
} else {
_hasAuthenticationFailed = false; // Reset failure state
}
@ -90,8 +96,8 @@ class _LockScreenState extends State<LockScreen> with WidgetsBindingObserver {
super.dispose();
}
Future<void> _showLockScreen() async {
_logger.info("Showing lock screen");
Future<void> _showLockScreen({String source = ''}) async {
_logger.info("Showing lock screen $source");
try {
_isShowingLockScreen = true;
final result = await requestAuthentication(
@ -100,6 +106,7 @@ class _LockScreenState extends State<LockScreen> with WidgetsBindingObserver {
);
_isShowingLockScreen = false;
if (result) {
lastAuthenticatingTime = DateTime.now().millisecondsSinceEpoch;
AppLock.of(context)!.didUnlock();
} else {
_logger.info("Dismissed");