passcode_biometric_auth 0.0.2+1 copy "passcode_biometric_auth: ^0.0.2+1" to clipboard
passcode_biometric_auth: ^0.0.2+1 copied to clipboard

A Flutter package that combines both passcode and biometric authentications effectively.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:passcode_biometric_auth/passcode_biometric_auth.dart';

void main(List<String> args) {
  runApp(const MaterialApp(home: App()));
}

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

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  final auth = PasscodeBiometricAuthUICached(
    checkConfig: const CheckConfig(
      maxRetries: 5,
      waitWhenMaxRetriesExceeded: 30,
    ),
    onForgotPasscode: (context, authUI) async {
      if (await _forgotPasscode(context)) {
        return true;
      }
      return false;
    },
  );

  static Future<bool> _forgotPasscode(BuildContext context) async {
    final result = await showDialog<bool>(
        context: context,
        builder: (ctx) {
          return AlertDialog(
            title: const Text('Forget Passcode'),
            content: const Text(
              'All of your local data will be removed when reset the passcode. Would you like to continue?',
              textAlign: TextAlign.justify,
            ),
            actions: [
              OutlinedButton(
                child: const Text('No'),
                onPressed: () {
                  Navigator.pop(ctx, false);
                },
              ),
              ElevatedButton(
                child: const Text('Yes'),
                onPressed: () {
                  Navigator.pop(ctx, true);
                },
              ),
            ],
          );
        });

    return result == true;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Passcode Biometric Auth'),
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            ElevatedButton(
              onPressed: () {
                auth.authenticate(context);
              },
              child: const Text('Authenticate'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                auth.changePasscode(context);
              },
              child: const Text('Change Passcode'),
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
0
points
1
downloads

Publisher

verified publisherlamnhan.dev

Weekly Downloads

A Flutter package that combines both passcode and biometric authentications effectively.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

crypto, flutter, local_auth, pinput, shared_preferences

More

Packages that depend on passcode_biometric_auth