authenticate method
- required String localizedReason,
- required Iterable<
AuthMessages> authMessages, - AuthenticationOptions options = const AuthenticationOptions(),
Authenticates the user with biometrics available on the device while also allowing the user to use device authentication - pin, pattern, passcode.
Returns true if the user successfully authenticated. Returns false if
the authentication completes, but the user failed the challenge with no
further effects. Platform implementations should throw a
LocalAuthException
for any other outcome, such as errors, cancelation,
or lockout. This may mean that for some platforms, the implementation will
never return false (e.g., if the only standard outcomes are success,
cancelation, or temporary lockout due to too many retries).
localizedReason
is the message to show to user while prompting them
for authentication. This is typically along the lines of: 'Please scan
your finger to access MyApp.'. This must not be empty.
Provide authMessages
if you want to
customize messages in the dialogs.
Provide options
for configuring further authentication related options.
Implementation
@override
Future<bool> authenticate({
required String localizedReason,
required Iterable<AuthMessages> authMessages,
AuthenticationOptions options = const AuthenticationOptions(),
}) async {
assert(localizedReason.isNotEmpty);
final Map<String, Object> args = <String, Object>{
'localizedReason': localizedReason,
'useErrorDialogs': options.useErrorDialogs,
'stickyAuth': options.stickyAuth,
'sensitiveTransaction': options.sensitiveTransaction,
'biometricOnly': options.biometricOnly,
};
args.addAll(const AndroidAuthMessages().args);
for (final AuthMessages messages in authMessages) {
if (messages is AndroidAuthMessages) {
args.addAll(messages.args);
}
}
return (await _channel.invokeMethod<bool>('authenticate', args)) ?? false;
}