iproov_flutter 2.0.0 copy "iproov_flutter: ^2.0.0" to clipboard
iproov_flutter: ^2.0.0 copied to clipboard

PlatformAndroidiOS
outdated

The iProov Biometrics SDK for Flutter, providing flexible authentication for identity assurance

example/lib/main.dart

import 'package:bmprogresshud/bmprogresshud.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:iproov_api_client/iproov_api_client.dart';
import 'package:iproov_flutter/iproov_flutter.dart';
import 'package:uuid/uuid.dart';

import 'credentials.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'iProov Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var _scanInProgress = false;

  // This code is for demo purposes only. Do not make API calls from the device
  // in production!
  final _apiClient = const ApiClient(baseUrl: baseUrl, apiKey: apiKey, secret: secret);

  void _getTokenAndLaunchIProov(AssuranceType assuranceType, ClaimType claimType, String userId) async {
    setState(() => _scanInProgress = true);
    ProgressHud.show(ProgressHudType.loading, 'Getting token...');

    String token;

    try {
      token = await _apiClient.getToken(assuranceType, claimType, userId);
    } on Exception catch (e) {
      setState(() => _scanInProgress = false);
      ProgressHud.dismiss();

      showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: const Text('Error'),
            content: Text(e.toString()),
            actions: [
              TextButton(
                child: const Text('OK'),
                onPressed: () => Navigator.pop(context),
              )
            ],
          );
        },
      );

      return;
    }

    const options = Options(ui: UiOptions(floatingPromptEnabled: true));

    _launchIProov(token, options);
  }

  void _launchIProov(String token, Options options) {
    final stream = IProov.launch(streamingUrl: _apiClient.baseUrl, token: token, options: options);

    stream.listen((event) {
      if (event.isFinal) {
        setState(() => _scanInProgress = false);
      }

      if (event is IProovEventConnecting) {
        ProgressHud.show(ProgressHudType.loading, 'Connecting...');
      } else if (event is IProovEventConnected) {
        ProgressHud.dismiss();
      } else if (event is IProovEventProcessing) {
        ProgressHud.show(ProgressHudType.progress, event.message);
        ProgressHud.updateProgress(event.progress, event.message);
      } else if (event is IProovEventCancelled) {
        ProgressHud.dismiss();
      } else if (event is IProovEventSuccess) {
        ProgressHud.showAndDismiss(ProgressHudType.success, 'Success!');
      } else if (event is IProovEventFailure) {
        ProgressHud.showAndDismiss(ProgressHudType.error, event.reason);
      } else if (event is IProovEventError) {
        ProgressHud.showAndDismiss(ProgressHudType.error, event.error.title ?? 'Error');
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
    return Scaffold(
      appBar: AppBar(
        title: const Text('iProov Example'),
      ),
      body: ProgressHud(
        isGlobalHud: true,
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              TextButton(
                child: const Text(
                  '🚀 Launch',
                  style: TextStyle(fontSize: 20.0),
                ),
                onPressed: _scanInProgress
                    ? null
                    : () {
                        // Generate a random UUID as the User ID for testing purposes
                        final userId = const Uuid().v1();
                        _getTokenAndLaunchIProov(
                          // livenessAssurance or genuinePresenceAssurance
                          AssuranceType.genuinePresenceAssurance,
                          // enrol or verify
                          ClaimType.enrol,
                          userId,
                        );
                      },
              )
            ],
          ),
        ),
      ),
    );
  }
}
20
likes
130
points
1.36k
downloads

Publisher

verified publisheriproov.com

Weekly Downloads

The iProov Biometrics SDK for Flutter, providing flexible authentication for identity assurance

Repository (GitHub)

Documentation

API reference

License

unknown (license)

Dependencies

flutter, image

More

Packages that depend on iproov_flutter