Select Git revision
main.dart 2.61 KiB
import 'package:biometric_authenticator/biometric_authenticator.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Biometric Authentication Demo',
theme: ThemeData(
primarySwatch: Colors.indigo,
),
home: MyHomePage(title: 'Login using Biometric Method'),
);
}
}
class MyHomePage extends StatefulWidget {
String title;
MyHomePage({super.key, required this.title});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool isSupported = false;
bool? isAuthenticated;
@override
void initState() {
biometricLogin();
super.initState();
}
biometricLogin() async {
isSupported = await BiometricAuthentication().isDeviceSupported();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar:AppBar(
automaticallyImplyLeading: false,
title: Text(widget.title),
toolbarHeight: 80,
shape: Border.symmetric(horizontal: BorderSide(color: Theme.of(context).primaryColor)),
),
body: Center(
child: InkWell(
onTap: () async {
if(isSupported){
// BiometricAuthentication package usage for authenticate
isAuthenticated = await BiometricAuthentication().authenticate(title: 'Authenticate to Login');
if(isAuthenticated!){
// write your logic for successful authentication
Fluttertoast.showToast(msg: 'Login Successful');
}else{
Fluttertoast.showToast(msg: 'Login failed!!! Try Again');
}
}else{
Fluttertoast.showToast(msg: 'Device not supports Biometric Auth');
}