How to use fingerprint or touch ID in Flutter

We’ll learn how to perform Local authentication with a flutter app.

Basically, we’ll be using the Touch ID or Fingerprint authentication method.

Lets get to it.

Import the local_auth package from pub

Create a new dart file an paste this code:

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

class TouchID extends StatefulWidget {
  _TouchIDState createState() => _TouchIDState();

class _TouchIDState extends State<TouchID> {
  final LocalAuthentication localAuth = LocalAuthentication();
  bool _canCheckBiometric = false;
  String _authorizeText = 'Not Authorized!';

  List<BiometricType> availableBiometrics = List<BiometricType>();

  Future<void> _authorize() async {
    bool _isAuthorized = false;
    try {
      _isAuthorized = await localAuth.authenticateWithBiometrics(
        localizedReason: 'Please authenticate to Complete this process',
        useErrorDialogs: true,
        stickyAuth: true,
    } on PlatformException catch (e) {

    if (!mounted) return;

    setState(() {
      if (_isAuthorized) {
        _authorizeText = "Authorized Successfully!";
      } else {
        _authorizeText = "Not Authorized!";

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Touch ID Auth Example')),
      body: Center(
          child: Column(
        children: <Widget>[
            padding: const EdgeInsets.all(8.0),
            child: Text(_authorizeText),
            child: Text('Authorize'),
            onPressed: _authorize,

In main.dart:

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return new MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Code Snippets',
      theme: new ThemeData(primarySwatch:,
      home: new TouchID(),

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.

Add a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.