Last updated:
0 purchases
biometric authentication
Biometric Authentication Service for Flutter #
biometric_authentication #
Flutter package that integrates biometric authentication (face, fingerprint, pattern or password) into your app.
Features #
We get a popup for biometric authentication when we click the elevated button, and then using a callback function, we can navigate from there after a successful authentication.
After successfully authenticating by face, finger or password/pattern, depending on the mobile setting, you can navigate
Getting started #
Import
import 'package:biometric_authentication/biometric_authentication.dart';
copied to clipboard
Android Integration #
The plugin will build and run on SDK 16+, but isDeviceSupported() will always return false before SDK 23 (Android 6.0).
Activity Changes #
Note that biometric_authentication requires the use of a FragmentActivity instead of an Activity. To update your application:
If you are using FlutterActivity directly, change it to FlutterFragmentActivity in your AndroidManifest.xml.
If you are using a custom activity, update your MainActivity.java:
import io.flutter.embedding.android.FlutterFragmentActivity;
public class MainActivity extends FlutterFragmentActivity {
// ...
}
copied to clipboard
or MainActivity.kt:
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity: FlutterFragmentActivity() {
// ...
}
copied to clipboard
to inherit from FlutterFragmentActivity.
Permissions #
Update your project's AndroidManifest.xml file to include the USE_BIOMETRIC permissions:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
<manifest>
copied to clipboard
Usage #
To use this package, add biometric_authentication as a dependency in your pubspec.yaml file.
dependencies:
biometric_authentication: ^1.0.5
copied to clipboard
Additional information #
Example
import 'package:flutter/material.dart';
import 'package:biometric_authentication/biometric_authentication.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Biometric Auth Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Biometric Auth Example'),
),
body: Center(
child: BiometricAuthService(
title: 'Biometric Authentication',
onAuthentication: (bool isAuthenticated) {
// Handle authentication status here
if (isAuthenticated) {
//authentication completed than move that to the next screen
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => const SecondScreen()),
);
// Authentication successful
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Authentication successful'),
duration: Duration(seconds: 2),
),
);
} else {
// Authentication failed
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Authentication failed'),
duration: Duration(seconds: 2),
),
);
}
},
),
),
);
}
}
//screen showed if the authentication completed successfully
import 'package:flutter/material.dart';
class SecondScreen extends StatelessWidget {
const SecondScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Screen'),
),
//text after successful authentication of any biometric
body: const Center(
child: Text('Welcome to the second screen!'),
),
);
}
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.