Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
signin_with_biometric_view.dart
Go to the documentation of this file.
1import 'package:connect/core/localization/app_localizations.dart';
2import 'package:flutter/material.dart';
3import 'package:flutter_bloc/flutter_bloc.dart';
4import 'package:flutter_screenutil/flutter_screenutil.dart';
5import 'package:local_auth/local_auth.dart';
6
7import '../../../../../../core/services/biometric_service.dart';
8import '../../../../../../core/ui/widgets/custom_snackbar.dart';
9import '../../../../domain/enum/supported_biometric_type_enum.dart';
10import '../../../logic/authentication_bloc/authentication_bloc.dart';
11import '../widgets/biometric_button.dart';
12
13class SigninWithBiometricView extends StatefulWidget {
15 super.key,
16 });
17
18 @override
19 State<SigninWithBiometricView> createState() =>
20 _SigninWithBiometricViewState();
21}
22
23class _SigninWithBiometricViewState extends State<SigninWithBiometricView> {
24 List<BiometricType> _availableBiometrics = [];
25
26 @override
27 void initState() {
29 super.initState();
30 }
31
33
34 Future<void> _checkAvailableBiometrics() async {
36 final biometrics = await biometricService.getAvailableBiometrics();
37 final hasFingerprint = await biometricService.hasFingerprintSupport();
38 for (final type in biometrics) {
39 if (type == BiometricType.face) {
40 _availableBiometrics.add(BiometricType.face);
41 } else if (type == BiometricType.fingerprint ||
42 (type == BiometricType.strong && hasFingerprint)) {
43 _availableBiometrics.add(BiometricType.fingerprint);
44 }
45 }
46 setState(() {});
47 }
48
49 Future<void> _authenticate(BiometricType type) async {
50 final authenticated =
51 await biometricService.authenticate(type, 'Authenticate using $type');
52 if (!mounted) return;
53 if (authenticated) {
54 context.read<AuthenticationBloc>().add(LoadCredentialsEvent());
55 } else {
57 context,
58 Theme.of(context).colorScheme.error,
59 AppLocalizations.of(context)
60 .translate('Failed to authenticate using biometrics'),
61 );
62 }
63 }
64
65 @override
66 Widget build(BuildContext context) {
67 return Column(
68 children: [
69 Text(
70 AppLocalizations.of(context)
71 .translate('Log in with ease using your biometrics'),
72 style: Theme.of(context).textTheme.bodySmall?.copyWith(
73 color: Theme.of(context).hintColor,
74 ),
75 ),
76 SizedBox(height: 20.sp),
78 ? SizedBox()
79 : Row(
80 crossAxisAlignment: CrossAxisAlignment.center,
81 mainAxisAlignment: MainAxisAlignment.center,
82 children: [
83 SizedBox(height: 15.sp),
84 ..._availableBiometrics.map((biometric) {
85 final supportedType = biometric == BiometricType.face
86 ? SupportedBiometricType.face
87 : SupportedBiometricType.fingerprint;
88 return BiometricButton(
89 icon: supportedType.icon,
90 onPressed: () => _authenticate(biometric),
91 );
92 }),
93 ],
94 ),
95 ],
96 );
97 }
98}
abstract class BiometricService LocalBiometricService()
String translate(String key)
static AppLocalizations of(BuildContext context)
static display(final BuildContext context, final Color color, final String message,)
const SigninWithBiometricView({ super.key, })
override State< SigninWithBiometricView > createState()
override void initState()
final Color color
Definition failures.dart:1
override Widget build(BuildContext context)
class SigninWithBiometricView extends StatefulWidget _availableBiometrics
Future< void > _authenticate(BiometricType type) async
Future< void > _checkAvailableBiometrics() async