biometric_callback 1.0.0 copy "biometric_callback: ^1.0.0" to clipboard
biometric_callback: ^1.0.0 copied to clipboard

Biometric Auth Callback can easily track every fail and success.

example/lib/main.dart

import 'dart:async';
import 'dart:convert';
import 'dart:io' show Platform;

import 'package:biometric_callback/biometric_callback.dart';
import 'package:biometric_callback/model/biometric_auth_result.dart';
import 'package:biometric_callback/util/enum.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  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(
          iosPolicy: IOSPolicy.deviceOwnerAuthenticationWithBiometrics,
        );
        debugPrint(bioMetrciAuthResult?.isSuccess.toString() ?? "");
        debugPrint("error code : ${bioMetrciAuthResult?.errorCode ?? ""}");
        setState(() {});
      } catch (e) {
        debugPrint(" error : ${e.toString()}");
      }
    } else {
      try {
        eventSubscription =
            _biometricCallback.getBiometricAuthEvent(pinEnable: true).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') {
              debugPrint("EventData :: $eventData");
              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();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text(
            'Biometric Auth Callback',
          ),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'isSucsss :: ${bioMetrciAuthResult?.isSuccess ?? ""}\n',
              ),
              Text(
                'result :: ${bioMetrciAuthResult?.message ?? ""}\n',
              ),
              ElevatedButton(
                  onPressed: () {
                    biometricResult();
                  },
                  child: Text('check')),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
120
points
62
downloads

Publisher

unverified uploader

Weekly Downloads

Biometric Auth Callback can easily track every fail and success.

Documentation

API reference

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on biometric_callback