Skip to content

Commit

Permalink
Fix lock screen with PIN
Browse files Browse the repository at this point in the history
  • Loading branch information
bbedward committed May 4, 2020
1 parent fd0ea35 commit 78252dd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
96 changes: 50 additions & 46 deletions lib/ui/lock_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,42 @@ class _AppLockScreenState extends State<AppLockScreen> {
}
}

Future<void> authenticateWithBiometrics() async {
bool authenticated = await sl.get<BiometricUtil>().authenticateWithBiometrics(context, AppLocalization.of(context).unlockBiometricsKal);
if (authenticated) {
_goHome();
} else {
setState(() {
_showUnlockButton = true;
});
}
}

Future<void> authenticateWithPin({bool transitions = false}) async {
String expectedPin = await sl.get<Vault>().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<void> _authenticate({bool transitions = false}) async {
// Test if user is locked out
// Get duration of lockout
Expand All @@ -140,54 +176,22 @@ class _AppLockScreenState extends State<AppLockScreen> {
setState(() {
_lockedOut = false;
});
sl.get<SharedPrefsUtil>().getAuthMethod().then((authMethod) {
sl.get<BiometricUtil>().hasBiometrics().then((hasBiometrics) {
if (authMethod.method == AuthMethod.BIOMETRICS && hasBiometrics) {
setState(() {
_showLock = true;
_showUnlockButton = true;
});
sl.get<BiometricUtil>().authenticateWithBiometrics(context,
AppLocalization.of(context).unlockBiometricsKal)
.then((authenticated) {
if (authenticated) {
_goHome();
} else {
setState(() {
_showUnlockButton = true;
});
}
});
} else {
// PIN Authentication
sl.get<Vault>().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<SharedPrefsUtil>().getAuthMethod();
bool hasBiometrics = await sl.get<BiometricUtil>().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();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 78252dd

Please sign in to comment.