flutter_reprint 1.0.3 copy "flutter_reprint: ^1.0.3" to clipboard
flutter_reprint: ^1.0.3 copied to clipboard

A plugin to use Reprint in Flutter apps. Reprint is a fingerprint authentication library for Android that supports older devices (for example, Samsung S5 and Xiaomi Redmi 3).

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:flutter_reprint/flutter_reprint.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _fingerprintReaderAvailable = "NO";
  String _authStatus = '';
  bool isErrorMessage = false;

  TextStyle authMessageStyle,
      regularAuthMessageStyle = TextStyle(
    color: Colors.indigoAccent,
  );

  TextStyle errorAuthMessageStyle = TextStyle(
    color: Colors.red,
    fontWeight: FontWeight.bold,
  );

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String fingerprintReaderAvailable;

    try {
      fingerprintReaderAvailable =
          (await FlutterReprint.canCheckFingerprint) ? 'YES' : 'NO';
    } on PlatformException {
      fingerprintReaderAvailable = "ERROR";
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _fingerprintReaderAvailable = fingerprintReaderAvailable;
    });
  }

  _updateAuthMessage(String message, {bool isError = false}) {
    setState(() {
      _authStatus = message;
      authMessageStyle =
          isError ? errorAuthMessageStyle : regularAuthMessageStyle;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('flutter_reprint example app'),
        ),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: ListView(
              children: <Widget>[
                Center(
                  child: Text(
                      'Fingerprint reader available: $_fingerprintReaderAvailable\n'),
                ),
                RaisedButton(
                  child: Text(
                    'Authenticate',
                  ),
                  onPressed: () async {
                    _updateAuthMessage('Waiting for fingerprint');

                    FlutterReprint.authenticateWithBiometrics()
                        .then((authResult) {
                      _updateAuthMessage(
                          authResult.success
                              ? "SUCCESS"
                              : "FAILED: ${authResult.failureReason}",
                          isError: !authResult.success);
                    });
                  },
                ),
                RaisedButton(
                    child: Text(
                      'Stop authentication',
                    ),
                    onPressed: () {
                      try {
                        FlutterReprint.stopAuthentication().then((cancelOK) {
                          _updateAuthMessage(cancelOK
                              ? "Authentication stopped"
                              : "Authentication was not happening");
                        });
                      } on PlatformException catch (e) {
                        _updateAuthMessage(e.message, isError: true);
                      }
                    }),
                Center(
                  child: Text(
                    _authStatus,
                    style: authMessageStyle,
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
4
likes
40
pub points
0%
popularity

Publisher

unverified uploader

A plugin to use Reprint in Flutter apps. Reprint is a fingerprint authentication library for Android that supports older devices (for example, Samsung S5 and Xiaomi Redmi 3).

Repository (GitHub)
View/report issues

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on flutter_reprint