@@ -12,14 +12,11 @@ import 'dart:async';
1212
1313import 'package:flutter/foundation.dart' show visibleForTesting;
1414import 'package:flutter/services.dart' ;
15+ import 'package:local_auth_platform_interface/local_auth_platform_interface.dart' ;
1516import 'package:platform/platform.dart' ;
16-
1717import 'auth_strings.dart' ;
18- import 'error_codes.dart' ;
19-
20- enum BiometricType { face, fingerprint, iris }
2118
22- const MethodChannel _channel = MethodChannel ( 'plugins.flutter.io/local_auth' ) ;
19+ export 'package:local_auth_platform_interface/types/biometric_type.dart' ;
2320
2421Platform _platform = const LocalPlatform ();
2522
@@ -31,7 +28,7 @@ void setMockPathProviderPlatform(Platform platform) {
3128/// A Flutter plugin for authenticating the user identity locally.
3229class LocalAuthentication {
3330 /// The `authenticateWithBiometrics` method has been deprecated.
34- /// Use `authenticate` with `biometricOnly: true` instead
31+ /// Use `authenticate` with `biometricOnly: true` instead.
3532 @Deprecated ('Use `authenticate` with `biometricOnly: true` instead' )
3633 Future <bool > authenticateWithBiometrics ({
3734 required String localizedReason,
@@ -41,21 +38,21 @@ class LocalAuthentication {
4138 IOSAuthMessages iOSAuthStrings = const IOSAuthMessages (),
4239 bool sensitiveTransaction = true ,
4340 }) =>
44- authenticate (
41+ LocalAuthPlatform .instance. authenticate (
4542 localizedReason: localizedReason,
46- useErrorDialogs: useErrorDialogs,
47- stickyAuth: stickyAuth,
48- androidAuthStrings: androidAuthStrings,
49- iOSAuthStrings: iOSAuthStrings,
50- sensitiveTransaction: sensitiveTransaction,
51- biometricOnly: true ,
43+ authMessages: < AuthMessages > [iOSAuthStrings, androidAuthStrings],
44+ options: AuthenticationOptions (
45+ useErrorDialogs: useErrorDialogs,
46+ stickyAuth: stickyAuth,
47+ sensitiveTransaction: sensitiveTransaction,
48+ biometricOnly: true ,
49+ ),
5250 );
5351
5452 /// Authenticates the user with biometrics available on the device while also
5553 /// allowing the user to use device authentication - pin, pattern, passcode.
5654 ///
57- /// Returns a [Future] holding true, if the user successfully authenticated,
58- /// false otherwise.
55+ /// Returns true, if the user successfully authenticated, false otherwise.
5956 ///
6057 /// [localizedReason] is the message to show to user while prompting them
6158 /// for authentication. This is typically along the lines of: 'Please scan
@@ -99,29 +96,17 @@ class LocalAuthentication {
9996 IOSAuthMessages iOSAuthStrings = const IOSAuthMessages (),
10097 bool sensitiveTransaction = true ,
10198 bool biometricOnly = false ,
102- }) async {
103- assert (localizedReason.isNotEmpty);
104-
105- final Map <String , Object > args = < String , Object > {
106- 'localizedReason' : localizedReason,
107- 'useErrorDialogs' : useErrorDialogs,
108- 'stickyAuth' : stickyAuth,
109- 'sensitiveTransaction' : sensitiveTransaction,
110- 'biometricOnly' : biometricOnly,
111- };
112- if (_platform.isIOS) {
113- args.addAll (iOSAuthStrings.args);
114- } else if (_platform.isAndroid) {
115- args.addAll (androidAuthStrings.args);
116- } else {
117- throw PlatformException (
118- code: otherOperatingSystem,
119- message: 'Local authentication does not support non-Android/iOS '
120- 'operating systems.' ,
121- details: 'Your operating system is ${_platform .operatingSystem }' ,
122- );
123- }
124- return (await _channel.invokeMethod <bool >('authenticate' , args)) ?? false ;
99+ }) {
100+ return LocalAuthPlatform .instance.authenticate (
101+ localizedReason: localizedReason,
102+ authMessages: < AuthMessages > [iOSAuthStrings, androidAuthStrings],
103+ options: AuthenticationOptions (
104+ useErrorDialogs: useErrorDialogs,
105+ stickyAuth: stickyAuth,
106+ sensitiveTransaction: sensitiveTransaction,
107+ biometricOnly: biometricOnly,
108+ ),
109+ );
125110 }
126111
127112 /// Returns true if auth was cancelled successfully.
@@ -131,52 +116,30 @@ class LocalAuthentication {
131116 /// Returns [Future] bool true or false:
132117 Future <bool > stopAuthentication () async {
133118 if (_platform.isAndroid) {
134- return await _channel. invokeMethod < bool >( ' stopAuthentication' ) ?? false ;
119+ return LocalAuthPlatform .instance. stopAuthentication () ;
135120 }
136121 return true ;
137122 }
138123
139124 /// Returns true if device is capable of checking biometrics
140125 ///
141126 /// Returns a [Future] bool true or false:
142- Future <bool > get canCheckBiometrics async =>
143- (await _channel.invokeListMethod <String >('getAvailableBiometrics' ))!
144- .isNotEmpty;
127+ Future <bool > get canCheckBiometrics =>
128+ LocalAuthPlatform .instance.deviceSupportsBiometrics ();
145129
146130 /// Returns true if device is capable of checking biometrics or is able to
147131 /// fail over to device credentials.
148132 ///
149133 /// Returns a [Future] bool true or false:
150134 Future <bool > isDeviceSupported () async =>
151- ( await _channel. invokeMethod < bool >( ' isDeviceSupported' )) ?? false ;
135+ LocalAuthPlatform .instance. isDeviceSupported () ;
152136
153137 /// Returns a list of enrolled biometrics
154138 ///
155139 /// Returns a [Future] List<BiometricType> with the following possibilities:
156140 /// - BiometricType.face
157141 /// - BiometricType.fingerprint
158142 /// - BiometricType.iris (not yet implemented)
159- Future <List <BiometricType >> getAvailableBiometrics () async {
160- final List <String > result = (await _channel.invokeListMethod <String >(
161- 'getAvailableBiometrics' ,
162- )) ??
163- < String > [];
164- final List <BiometricType > biometrics = < BiometricType > [];
165- for (final String value in result) {
166- switch (value) {
167- case 'face' :
168- biometrics.add (BiometricType .face);
169- break ;
170- case 'fingerprint' :
171- biometrics.add (BiometricType .fingerprint);
172- break ;
173- case 'iris' :
174- biometrics.add (BiometricType .iris);
175- break ;
176- case 'undefined' :
177- break ;
178- }
179- }
180- return biometrics;
181- }
143+ Future <List <BiometricType >> getAvailableBiometrics () =>
144+ LocalAuthPlatform .instance.getEnrolledBiometrics ();
182145}
0 commit comments