local_auth 0.6.1+3

  • Readme
  • Changelog
  • Example
  • Installing
  • 99

local_auth #

This Flutter plugin provides means to perform local, on-device authentication of the user.

This means referring to biometric authentication on iOS (Touch ID or lock code) and the fingerprint APIs on Android (introduced in Android 6.0).

Usage in Dart #

Import the relevant file:

import 'package:local_auth/local_auth.dart';

To check whether there is local authentication available on this device or not, call canCheckBiometrics:

bool canCheckBiometrics =
    await localAuth.canCheckBiometrics;

Currently the following biometric types are implemented:

  • BiometricType.face
  • BiometricType.fingerprint

To get a list of enrolled biometrics, call getAvailableBiometrics:

List<BiometricType> availableBiometrics =
    await auth.getAvailableBiometrics();

if (Platform.isIOS) {
    if (availableBiometrics.contains(BiometricType.face)) {
        // Face ID.
    } else if (availableBiometrics.contains(BiometricType.fingerprint)) {
        // Touch ID.

We have default dialogs with an 'OK' button to show authentication error messages for the following 2 cases:

  1. Passcode/PIN/Pattern Not Set. The user has not yet configured a passcode on iOS or PIN/pattern on Android.
  2. Touch ID/Fingerprint Not Enrolled. The user has not enrolled any fingerprints on the device.

Which means, if there's no fingerprint on the user's device, a dialog with instructions will pop up to let the user set up fingerprint. If the user clicks 'OK' button, it will return 'false'.

Use the exported APIs to trigger local authentication with default dialogs:

var localAuth = LocalAuthentication();
bool didAuthenticate =
    await localAuth.authenticateWithBiometrics(
        localizedReason: 'Please authenticate to show account balance');

If you don't want to use the default dialogs, call this API with 'useErrorDialogs = false'. In this case, it will throw the error message back and you need to handle them in your dart code:

bool didAuthenticate =
    await localAuth.authenticateWithBiometrics(
        localizedReason: 'Please authenticate to show account balance',
        useErrorDialogs: false);

You can use our default dialog messages, or you can use your own messages by passing in IOSAuthMessages and AndroidAuthMessages:

import 'package:local_auth/auth_strings.dart';

const iosStrings = const IOSAuthMessages(
    cancelButton: 'cancel',
    goToSettingsButton: 'settings',
    goToSettingsDescription: 'Please set up your Touch ID.',
    lockOut: 'Please reenable your Touch ID');
await localAuth.authenticateWithBiometrics(
    localizedReason: 'Please authenticate to show account balance',
    useErrorDialogs: false,
    iOSAuthStrings: iosStrings);

If needed, you can manually stop authentication for android:

void _cancelAuthentication() {

Exceptions #

There are 6 types of exceptions: PasscodeNotSet, NotEnrolled, NotAvailable, OtherOperatingSystem, LockedOut and PermanentlyLockedOut. They are wrapped in LocalAuthenticationError class. You can catch the exception and handle them by different types. For example:

import 'package:flutter/services.dart';
import 'package:local_auth/error_codes.dart' as auth_error;

try {
  bool didAuthenticate = await local_auth.authenticateWithBiometrics(
      localizedReason: 'Please authenticate to show account balance');
} on PlatformException catch (e) {
  if (e.code == auth_error.notAvailable) {
    // Handle this exception here.

iOS Integration #

Note that this plugin works with both TouchID and FaceID. However, to use the latter, you need to also add:

<string>Why is my app authenticating using face id?</string>

to your Info.plist file. Failure to do so results in a dialog that tells the user your app has not been updated to use TouchID.

Android Integration #

Note that local_auth plugin requires the use of a FragmentActivity as opposed to Activity. This can be easily done by switching to use FlutterFragmentActivity as opposed to FlutterActivity in your manifest (or your own Activity class if you are extending the base class).

Update your project's AndroidManifest.xml file to include the USE_FINGERPRINT permissions:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  <uses-permission android:name="android.permission.USE_FINGERPRINT"/>

On Android, you can check only for existence of fingerprint hardware prior to API 29 (Android Q). Therefore, if you would like to support other biometrics types (such as face scanning) and you want to support SDKs lower than Q, do not call getAvailableBiometrics. Simply call authenticateWithBiometrics. This will return an error if there was no hardware available.

Sticky Auth #

You can set the stickyAuth option on the plugin to true so that plugin does not return failure if the app is put to background by the system. This might happen if the user receives a phone call before they get a chance to authenticate. With stickyAuth set to false, this would result in plugin returning failure result to the Dart app. If set to true, the plugin will retry authenticating when the app resumes.

Getting Started #

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

0.6.1+3 #

  • Make the pedantic dev_dependency explicit.

0.6.1+2 #

  • Support v2 embedding.

0.6.1+1 #

  • Remove the deprecated author: field from pubspec.yaml
  • Migrate the plugin to the pubspec platforms manifest.
  • Require Flutter SDK 1.10.0 or greater.

0.6.1 #

  • Added ability to stop authentication (For Android).

0.6.0+3 #

  • Remove AndroidX warnings.

0.6.0+2 #

  • Update and migrate iOS example project.
  • Define clang module for iOS.

0.6.0+1 #

  • Update the intl constraint to ">=0.15.1 <0.17.0" (0.16.0 isn't really a breaking change).

0.6.0 #

  • Define a new parameter for signaling that the transaction is sensitive.
  • Up the biometric version to beta01.
  • Handle no device credential error.

0.5.3 #

  • Add face id detection as well by not relying on FingerprintCompat.

0.5.2+4 #

  • Update README to fix syntax error.

0.5.2+3 #

  • Update documentation to clarify the need for FragmentActivity.

0.5.2+2 #

  • Add missing template type parameter to invokeMethod calls.
  • Bump minimum Flutter version to 1.5.0.
  • Replace invokeMethod with invokeMapMethod wherever necessary.

0.5.2+1 #

  • Use post instead of postDelayed to show the dialog onResume.

0.5.2 #

  • Executor thread needs to be UI thread.

0.5.1 #

  • Fix crash on Android versions earlier than 28.
  • authenticateWithBiometrics will not return result unless Biometric Dialog is closed.
  • Added two more error codes LockedOut and PermanentlyLockedOut.

0.5.0 #

  • Breaking change. Update the Android API to use androidx Biometric package. This gives the prompt the updated Material look. However, it also requires the activity to be a FragmentActivity. Users can switch to FlutterFragmentActivity in their main app to migrate.

0.4.0+1 #

  • Log a more detailed warning at build time about the previous AndroidX migration.

0.4.0 #

  • Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.

0.3.1 #

  • Fix crash on Android versions earlier than 24.

0.3.0 #

  • Breaking change. Add canCheckBiometrics and getAvailableBiometrics which leads to a new API.

0.2.1 #

  • Updated Gradle tooling to match Android Studio 3.1.2.

0.2.0 #

  • Breaking change. Set SDK constraints to match the Flutter beta release.

0.1.2 #

  • Fixed Dart 2 type error.

0.1.1 #

  • Simplified and upgraded Android project template to Android SDK 27.
  • Updated package description.

0.1.0 #

  • Breaking change. Upgraded to Gradle 4.1 and Android Studio Gradle plugin 3.0.1. Older Flutter projects need to upgrade their Gradle setup as well in order to use this version of the plugin. Instructions can be found here.

0.0.3 #

  • Add FLT prefix to iOS types

0.0.2+1 #

  • Update messaging to support Face ID.

0.0.2 #

  • Support stickyAuth mode.

0.0.1 #

  • Initial release of local authentication plugin.


// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:local_auth/local_auth.dart';

void main() {

class MyApp extends StatefulWidget {
  _MyAppState createState() => _MyAppState();

class _MyAppState extends State<MyApp> {
  final LocalAuthentication auth = LocalAuthentication();
  bool _canCheckBiometrics;
  List<BiometricType> _availableBiometrics;
  String _authorized = 'Not Authorized';
  bool _isAuthenticating = false;

  Future<void> _checkBiometrics() async {
    bool canCheckBiometrics;
    try {
      canCheckBiometrics = await auth.canCheckBiometrics;
    } on PlatformException catch (e) {
    if (!mounted) return;

    setState(() {
      _canCheckBiometrics = canCheckBiometrics;

  Future<void> _getAvailableBiometrics() async {
    List<BiometricType> availableBiometrics;
    try {
      availableBiometrics = await auth.getAvailableBiometrics();
    } on PlatformException catch (e) {
    if (!mounted) return;

    setState(() {
      _availableBiometrics = availableBiometrics;

  Future<void> _authenticate() async {
    bool authenticated = false;
    try {
      setState(() {
        _isAuthenticating = true;
        _authorized = 'Authenticating';
      authenticated = await auth.authenticateWithBiometrics(
          localizedReason: 'Scan your fingerprint to authenticate',
          useErrorDialogs: true,
          stickyAuth: true);
      setState(() {
        _isAuthenticating = false;
        _authorized = 'Authenticating';
    } on PlatformException catch (e) {
    if (!mounted) return;

    final String message = authenticated ? 'Authorized' : 'Not Authorized';
    setState(() {
      _authorized = message;

  void _cancelAuthentication() {

  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
      body: ConstrainedBox(
          constraints: const BoxConstraints.expand(),
          child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: <Widget>[
                Text('Can check biometrics: $_canCheckBiometrics\n'),
                  child: const Text('Check biometrics'),
                  onPressed: _checkBiometrics,
                Text('Available biometrics: $_availableBiometrics\n'),
                  child: const Text('Get available biometrics'),
                  onPressed: _getAvailableBiometrics,
                Text('Current State: $_authorized\n'),
                  child: Text(_isAuthenticating ? 'Cancel' : 'Authenticate'),
                      _isAuthenticating ? _cancelAuthentication : _authenticate,

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  local_auth: ^0.6.1+3

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:local_auth/local_auth.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
flutter_plugin_android_lifecycle ^1.0.2 1.0.6
intl >=0.15.1 <0.17.0 0.16.1
meta ^1.0.5 1.1.8
platform ^2.0.0 2.2.1
Transitive dependencies
collection 1.14.11 1.14.12
path 1.6.4
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
e2e ^0.2.1
pedantic ^1.8.0