From 78252dd7b950cb1fce6fa4e38d9bd85ecb8810a5 Mon Sep 17 00:00:00 2001 From: bbedward Date: Sun, 3 May 2020 22:11:28 -0400 Subject: [PATCH] Fix lock screen with PIN --- lib/ui/lock_screen.dart | 96 +++++++++++++++++++++-------------------- pubspec.yaml | 2 +- 2 files changed, 51 insertions(+), 47 deletions(-) diff --git a/lib/ui/lock_screen.dart b/lib/ui/lock_screen.dart index 5b66f10e..1ba195db 100644 --- a/lib/ui/lock_screen.dart +++ b/lib/ui/lock_screen.dart @@ -123,6 +123,42 @@ class _AppLockScreenState extends State { } } + Future authenticateWithBiometrics() async { + bool authenticated = await sl.get().authenticateWithBiometrics(context, AppLocalization.of(context).unlockBiometricsKal); + if (authenticated) { + _goHome(); + } else { + setState(() { + _showUnlockButton = true; + }); + } + } + + Future authenticateWithPin({bool transitions = false}) async { + String expectedPin = await sl.get().getPin(); + if (transitions) { + Navigator.of(context).push( + MaterialPageRoute(builder: (BuildContext context) { + return _buildPinScreen(context, expectedPin); + }), + ); + } else { + Navigator.of(context).push( + NoPushTransitionRoute(builder: (BuildContext context) { + return _buildPinScreen(context, expectedPin); + }), + ); + } + Future.delayed(Duration(milliseconds: 200), () { + if (mounted) { + setState(() { + _showUnlockButton = true; + _showLock = true; + }); + } + }); + } + Future _authenticate({bool transitions = false}) async { // Test if user is locked out // Get duration of lockout @@ -140,54 +176,22 @@ class _AppLockScreenState extends State { setState(() { _lockedOut = false; }); - sl.get().getAuthMethod().then((authMethod) { - sl.get().hasBiometrics().then((hasBiometrics) { - if (authMethod.method == AuthMethod.BIOMETRICS && hasBiometrics) { - setState(() { - _showLock = true; - _showUnlockButton = true; - }); - sl.get().authenticateWithBiometrics(context, - AppLocalization.of(context).unlockBiometricsKal) - .then((authenticated) { - if (authenticated) { - _goHome(); - } else { - setState(() { - _showUnlockButton = true; - }); - } - }); - } else { - // PIN Authentication - sl.get().getPin().then((expectedPin) { - if (transitions) { - Navigator.of(context).push( - MaterialPageRoute(builder: (BuildContext context) { - return _buildPinScreen(context, expectedPin); - }), - ); - } else { - Navigator.of(context).push( - NoPushTransitionRoute(builder: (BuildContext context) { - return _buildPinScreen(context, expectedPin); - }), - ); - } - Future.delayed(Duration(milliseconds: 200), () { - if (mounted) { - setState(() { - _showUnlockButton = true; - _showLock = true; - }); - } - }); - }); - } + AuthenticationMethod authMethod = await sl.get().getAuthMethod(); + bool hasBiometrics = await sl.get().hasBiometrics(); + if (authMethod.method == AuthMethod.BIOMETRICS && hasBiometrics) { + setState(() { + _showLock = true; + _showUnlockButton = true; }); - }); + try { + await authenticateWithBiometrics(); + } catch (e) { + await authenticateWithPin(transitions: transitions); + } + } else { + await authenticateWithPin(transitions: transitions); + } } - @override void initState() { super.initState(); diff --git a/pubspec.yaml b/pubspec.yaml index 1c1d79ef..5ddad7a9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,7 @@ description: A new Flutter project. # Both the version and the builder number may be overridden in flutter # build by specifying --build-name and --build-number, respectively. # Read more about versioning at semver.org. -version: 2.1.1+80 +version: 2.1.2+81 environment: sdk: ">=2.0.0-dev.68.0 <3.0.0"