Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
signin_with_biometric_view.dart
Go to the documentation of this file.
1import 'package:flutter/material.dart';
2import 'package:flutter_bloc/flutter_bloc.dart';
3import 'package:flutter_screenutil/flutter_screenutil.dart';
4import 'package:local_auth/local_auth.dart';
5
6import '../../../../../../core/common/enums/biometric_type_enum.dart';
7import '../../../../../../core/services/biometric_service.dart';
8import '../../../../../../core/ui/widgets/custom_snackbar.dart';
9import '../../../bloc/authentication_bloc/authentication_bloc.dart';
10import '../widgets/biomitric_auth_buttons.dart';
11
12class SigninWithBiometricView extends StatefulWidget {
14 super.key,
15 });
16
17 @override
18 State<SigninWithBiometricView> createState() =>
19 _SigninWithBiometricViewState();
20}
21
22class _SigninWithBiometricViewState extends State<SigninWithBiometricView> {
23 final List<BiometricType> _availableBiometrics = [];
24
25 @override
26 void initState() {
28 super.initState();
29 }
30
32
33 Future<void> _checkAvailableBiometrics() async {
35 final biometrics = await biometricService.getAvailableBiometrics();
36 final hasFingerprint = await biometricService.hasFingerprintSupport();
37 for (final type in biometrics) {
38 if (type == BiometricType.face) {
39 _availableBiometrics.add(BiometricType.face);
40 } else if (type == BiometricType.fingerprint || (type == BiometricType.strong && hasFingerprint)) {
41 _availableBiometrics.add(BiometricType.fingerprint);
42 }
43 }
44 setState(() {});
45 }
46
47 Future<void> _authenticate(BiometricType type) async {
48 final authenticated = await biometricService.authenticate(type, 'Authenticate using $type');
49 if (!mounted) return;
50 if (authenticated) {
51 context.read<AuthenticationBloc>().add(LoadCredentialsEvent());
52 } else {
54 context,
55 Theme.of(context).colorScheme.error,
56 'Failed to authenticate using biometrics',
57 );
58 }
59 }
60
61 @override
62 Widget build(BuildContext context) {
63 return Column(
64 children: [
66 'Log in with ease using your biometrics',
67 style: Theme.of(context).textTheme.bodySmall?.copyWith(
68 color: Theme.of(context).hintColor,
69 ),
70 ),
71 SizedBox(height: 20.sp),
73 ? SizedBox()
74 : Row(
75 crossAxisAlignment: CrossAxisAlignment.center,
76 mainAxisAlignment: MainAxisAlignment.center,
77 children: [
78 SizedBox(height: 15.sp),
79 ..._availableBiometrics.map((biometric) {
80 final supportedType = biometric == BiometricType.face
81 ? SupportedBiometricType.face
82 : SupportedBiometricType.fingerprint;
83 return BiometricButton(
84 icon: supportedType.icon,
85 onPressed: () => _authenticate(biometric),
86 );
87 }),
88 ],
89 ),
90 ],
91 );
92 }
93}
override void initState()
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
abstract class BiometricService LocalBiometricService()
static ScaffoldFeatureController< SnackBar, SnackBarClosedReason > display(final BuildContext context, final Color color, final String message,)
const SigninWithBiometricView({ super.key, })
override State< SigninWithBiometricView > createState()
final String type
final Color color
Definition failures.dart:1
class SigninWithBiometricView extends StatefulWidget _availableBiometrics
Future< void > _authenticate(BiometricType type) async
Future< void > _checkAvailableBiometrics() async
style Text( '${ 'scheduling.reference'.tr()}:${collection.internalCode}', style:Theme.of(context).textTheme.bodySmall,)
style SizedBox(height:2.h)
style Column(crossAxisAlignment:CrossAxisAlignment.end, children:[Container(padding:EdgeInsets.symmetric(horizontal:8.w, vertical:4.h), decoration:BoxDecoration(color:ColorPalette.tiffanyBlue.withValues(alpha:0.1), borderRadius:BorderRadius.circular(12),), child:Text(collection.type ?? '', style:Theme.of(context).textTheme.bodySmall?.copyWith(color:ColorPalette.tiffanyBlue, fontWeight:FontWeight.bold,),),),],)