verifai_sdk 1.1.0 copy "verifai_sdk: ^1.1.0" to clipboard
verifai_sdk: ^1.1.0 copied to clipboard

The official Flutter package for Verifai's mobile (iOS and Android) SDK's.

example/example.md

Example Verifai Flutter SDK #

When implementing the SDK the main concept you need to understand is what the lifecycle of the Verifai SDK is.

The lifecycle can be distilled into the following basic steps:

  • SDK Setup
  • Running the SDK
  • Result processing

Setup #

Before anything can be done or scanned we need to setup the SDK. The SDK has default values for many of it's features. So the main thing that needs to be setup is the licence. In the example we add the licence to a dart file. It's smart to have the licence in a separate file that you keep out of version control. This way the chances of elaking the licence are low.

So we create a variable in the licence.dart file and then import it into our main.dart (or wherever you setup the licence). Here's an example on what to put inside the licence.dart file, please not that you'll have to put your own licence in there that matches your iOS bundle identifier and Android package name. This licence is available in our dashboard after you've made your solutions. Check the main README for more info about this.

var verifaiLicence = '''=== Verifai Licence file V2 ===
VQUHzC3sNld8uy8pBHMTFtLxrItlQlkL+7wX3QdVi3tFlXgxUnJhqPD510hLplCxp83o6gwOftCm
...
...
...
YMInt2Wk0N9ggwcZCymW4q6pcAUtL4Y8eV2A+sRA8BybdhuqY1r50ZURQD51nnDPvABEQLwcB31R
HF/w/+n6SRQso55nIQSUX8uYP8WpJVmi+Gi9aA==''';

After that make sure it's imported

import 'package:verifai_sdk/verifai_sdk.dart';
import 'licence.dart';

the licence can then be set like this:

var api = CoreApi();
await api.setLicence(verifaiLicence);

Core Configuration #

The core's setup is done by setting it's Configuration object. All the values in the configuration object have default values. So if you want to just get up and running with the SDK you can skip this step. All the configuration options are defined in our documentation and in the main README of the SDK.

Because all the values have defaults it's ok to just pass the ones you want to change from the default ones:

api.configure(Configuration(
    enablePostCropping: true,
    enableVisualInspection: true,
    enableManual: false,
 ));

note: api here is the CoreApi object defined in the licence setting step.

NFC Configuration #

The NFC is setup by setting it's NfcConfiguration object. This object is one of the values passed when starting the NFC SDK. For all the configuration options please check the main README file.

An example of setting the NFC check to retrieve a copy of the document holder's photo on the document's chip.

var NfcConfiguration = NfcConfiguration(retrieveImage: true);

Liveness Configuration #

The liveness check setup is done by setting the values in the LivenessConfiguration object. Just like with the NFC SDK this value is passed along when starting the Liveness check. One of the main things you can control in this configuration is the checks that are performed. For all options please check out the main README file.

var checks = [
      LivenessCheck(
          type: LivenessCheckType.closeEyes, args: {"numberOfSeconds": 3}),
      LivenessCheck(
          type: LivenessCheckType.tilt, args: {"faceAngleRequirement": 5}),
    ];
var livenessConfiguration = LivenessConfiguration(showDismissButton: false, checks: checks);

Running the SDK #

Once everything is setup the way you want it then running the SDK is a straightforward process. Each SDK has a start function, with the NFC and Liveness modules allowing for the passing of configuration options.

The NFC and Liveness modules also require some extra information from the Core scan to be able to be run.

Starting the Core module #

Once the licence has been set then running the SDK is as simple as:

await api.start();

note: api here is the CoreApi object defined in the licence setting step.

Starting the NFC module #

When starting the NFC module you'll have to pass the result from the Core scan. And like mentioned before you can pass the configuration object as well. More details about the settings can be found in the README.

  void _startNfc() async {
    var api = NfcApi();
    var coreData = context.read<CoreResultImpl>().data;
    if (coreData.mrzData != null) {
      await api.start(NfcConfiguration(retrieveImage: true), coreData);
      Navigator.push(
        context,
        MaterialPageRoute(builder: (context) => const NfcResult()),
      );
    } else {
      print("No core mrz data");
    }
  }

Starting the liveness module #

When starting the lifeness module you can customize the checks being done. If you choose to perform a face matching check then you'll need to pass the user's face image to compare it to the selfie. More details about the settings can be found in the README.

  void _startLiveness() async {
    var api = LivenessApi();
    var checks = [
      LivenessCheck(
          type: LivenessCheckType.closeEyes, args: {"numberOfSeconds": 3}),
      LivenessCheck(
          type: LivenessCheckType.tilt, args: {"faceAngleRequirement": 5}),
    ];
    var image = context.read<CoreResultImpl>().data.frontImage;
    if (image != null) {
      checks.add(LivenessCheck(
          type: LivenessCheckType.faceMatching,
          args: {"documentImage": image}));
    }
    api.start(LivenessConfiguration(showDismissButton: false, checks: checks));
  }

Result processing #

After the setup and the start the SDK will do it's thing and lead the user trough the process of scanning their identification document. Depensing on the flow the user takes or the information necessary this can be a fairly quick process or it could take a few minutes. Especially because not all users have their documents handy and have to look for them or get a good scanning result.

Each module has a result api that notifies it's listener of the process having finished with a result. It will also notify if an error ocurred or if the process was cancelled.

In the example app we implement these result api into classes that implement ChangeNotifier. This allows us to use those classes to process the result after the scan is done and pass what we need to any views that might want to consume the data.

In the example app you can find these classes in the modeldata.dart file inside the lib folder.

Core result processing example #

// Define a class that will handle the results of the core coming in
class CoreResultImpl with ChangeNotifier implements CoreResultApi {
  CoreResultImpl() {
    CoreResultApi.setup(this);
  }

  var _data = CoreResult();
  CoreResult get data => _data;
  set data(CoreResult value) {
    print(value.mrzData?.firstName);
    print(value.mrzData?.lastName);
    print(value.backDocumentPosition?.bottomRight?.x);
    _data = value;
    notifyListeners();
  }

  @override
  void onSuccess(CoreResult result) {
    data = result;
  }

  @override
  void onCancelled() {
    print('cancelled');
  }

  @override
  void onError(String message) {
    throw Exception(message);
  }
}

NFC result processing example #

class NfcResultImpl with ChangeNotifier implements NfcResultApi {
  NfcResultImpl() {
    NfcResultApi.setup(this);
  }

  var _data = NfcResult();
  NfcResult get data => _data;
  set data(NfcResult value) {
    _data = value;
    notifyListeners();
  }

  @override
  void onSuccess(NfcResult result) {
    data = result;
  }

  @override
  void onCancelled() {
    print('cancelled');
  }

  @override
  void onError(String message) {
    print(message);
    throw Exception(message);
  }
}

Liveness result processing example #

class LivenessResultImpl with ChangeNotifier implements LivenessResultApi {
  LivenessResultImpl() {
    LivenessResultApi.setup(this);
  }

  var _data = LivenessResult();
  LivenessResult get data => _data;
  set data(LivenessResult value) {
    _data = value;
    notifyListeners();
  }

  @override
  void onSuccess(LivenessResult result) {
    data = result;
    print(result.automaticChecksPassed);
    print(result.successRatio);
    print(result.resultList);
  }

  @override
  void onError(String message) {
    print(message);
    throw Exception(message);
  }
}
10
likes
100
pub points
21%
popularity

Publisher

verified publisherverifai.com

The official Flutter package for Verifai's mobile (iOS and Android) SDK's.

Homepage

Documentation

Documentation
API reference

License

unknown (LICENSE)

Dependencies

flutter, pigeon, provider

More

Packages that depend on verifai_sdk