authenticate method

Future<bool> authenticate({
  1. required String localizedReason,
  2. Iterable<AuthMessages> authMessages = const <AuthMessages>[IOSAuthMessages(), AndroidAuthMessages(), WindowsAuthMessages()],
  3. bool biometricOnly = false,
  4. bool sensitiveTransaction = true,
  5. bool persistAcrossBackgrounding = false,
})
inherited

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.

If the user fails the authentication challenge without any side effects, returns false. For other other failures cases, throws a LocalAuthException with details about the reason it did not succeed.

localizedReason is the message to show to user while prompting them for authentication. This is typically along the lines of: 'Authenticate to access MyApp.'. This must not be empty.

Provide authMessages if you want to customize messages in the dialogs.

Set biometricOnly to true to prevent authentications from using non-biometric local authentication such as pin, passcode, or pattern.

sensitiveTransaction, which defaults to true, controls whether platform-specific precautions are enabled, such as showing a confirmation dialog after face unlock is recognized to make sure the user meant to unlock their device.

On mobile platforms, authentication may be stopped by the system when the app is backgrounded during an authentication. Set persistAcrossBackgrounding to true to have the plugin automatically retry the authentication on foregrounding instead of failing with an error on backgrounding.

Implementation

Future<bool> authenticate({
  required String localizedReason,
  Iterable<AuthMessages> authMessages = const <AuthMessages>[
    IOSAuthMessages(),
    AndroidAuthMessages(),
    WindowsAuthMessages(),
  ],
  bool biometricOnly = false,
  bool sensitiveTransaction = true,
  bool persistAcrossBackgrounding = false,
}) {
  return LocalAuthPlatform.instance.authenticate(
    localizedReason: localizedReason,
    authMessages: authMessages,
    options: AuthenticationOptions(
      stickyAuth: persistAcrossBackgrounding,
      biometricOnly: biometricOnly,
      sensitiveTransaction: sensitiveTransaction,
      // This is a legacy option; implementations compatible with 3.x plus
      // should always assume this is false, so set it accordingly.
      useErrorDialogs: false,
    ),
  );
}