Last updated:
0 purchases
biometric callback
Welcome to Biometric_callback Plugin! #
This Flutter plugin provides means to perform biometric authenticationo of the user.On supported devices, this includes authentication with biometrics such as fingerprint or facial recognition.Now It supports both for Android and iOS.
Android Permission
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
iOS Permission
Note that this plugin works with both Touch ID and Face ID. However, to use the latter, you need to also add:
<key>NSFaceIDUsageDescription</key>
<string>Why is my app authenticating using face id?</string>
copied to clipboard
Android Integration
Activity Changes
Note that Biometric_callback requires the use of a FragmentActivity instead of an Activity. To update your application:
Update your MainActivity.kt:
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterFragmentActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}
copied to clipboard
Optional
IOS
Device IOSPolicy deviceOwnerAuthenticationWithBiometrics owner will be authenticated using a biometric method (Touch ID or Face ID).
Using IOSPolicy deviceOwnerAuthentication Device owner will be authenticated by biometry or device passcode.
Android
Device PinEnable false will be authenticated using only biometric method.
Using PinEnable true Device owner will be authenticated by biometry and after fail it will show device passcode/Pattern.
Usages
Keep in mind that this depends on the platform, as in iOS LocalAuthentication is not provided with any callbacks and you only receive the final result, locked out, and any specified error_code.We need an event-based system because Android provides callbacks.You can therefore receive every callback as a result.
final _biometricCallback = BiometricCallback();
BiometricAuthResult? bioMetrciAuthResult;
///For android
StreamSubscription<dynamic>? eventSubscription;
@override
void initState() {
super.initState();
biometricResult();
}
Future<void> biometricResult() async {
if (Platform.isIOS) {
try {
bioMetrciAuthResult = await _biometricCallback.getBiometricAuthResult();
debugPrint(bioMetrciAuthResult?.isSuccess.toString() ?? "");
} catch (e) {
debugPrint(" error : ${e.toString()}");
}
} else {
try {
eventSubscription = _biometricCallback.getBiometricAuthEvent().listen(
(event) async {
// Handle the received event data
final String eventName = event['event'];
final dynamic eventData = event['data'];
if (eventName == 'success') {
bioMetrciAuthResult =
BiometricAuthResult.fromJson(jsonDecode(eventData));
} else if (eventName == 'error') {
bioMetrciAuthResult =
BiometricAuthResult.fromJson(jsonDecode(eventData));
}
setState(() {});
},
onError: (error) {
// Handle any error during event reception
debugPrint("flutter Errror :: $error");
},
cancelOnError: true, // Cancel the subscription on error
);
} catch (e) {
debugPrint(" error : ${e.toString()}");
}
}
}
@override
void dispose() {
super.dispose();
eventSubscription?.cancel();
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.