idcheckio 8.0.3 copy "idcheckio: ^8.0.3" to clipboard
idcheckio: ^8.0.3 copied to clipboard

A flutter plugin which simplify the integration of the IDCheck.io SDK into your flutter project.

example/lib/main.dart

import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:idcheckio/idcheckio.dart';
import 'package:idcheckio/idcheckio_api.dart';
import 'package:idcheckio_example/theme.dart';
import 'params.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 _activationToken = "4ISdBd6Ha1x/oyw6Cbss7KoZy9cQKKmAorBMXrtrTv12ooy/wJ5TxSWaJF7v2oGzFsSlZfss6ObaHH2T63AT2dqAx+vW1EHk22RkKtn+bAX0o3Pn6tYkNkBR5/rbrHqXAaHKyexzaTGeml+208D5Bf33msvg4LkvJh8TS1YxYA5RoBI=";
  final _idcheckioPlugin = IDCheckio();
  bool _sdkActivated = false;
  IDCheckioResult? _captureResult;
  String _onboardingFolderUid = "";
  late Function() _onboardingListener;
  TextEditingController onboardingController = new TextEditingController();
  late ParamsListItem _selectedItem;
  late SdkColor _selectedTheme;
  late List<DropdownMenuItem<ParamsListItem>> _dropdownMenuItems;
  late List<DropdownMenuItem<SdkColor>> _dropdownThemeItems;
  List<SdkColor> _dropdownTheme = [
    SdkColor.DEFAULT,
    SdkColor.BLUE,
    SdkColor.PURPLE,
    SdkColor.DARK_GOLD
  ];
  List<ParamsListItem> _dropdownItems = [
    ParamsListItem("ID", paramsID),
    ParamsListItem("Liveness", paramsLiveness),
    ParamsListItem("Start Onboarding", null)..isOnboarding = true,
    ParamsListItem("French health card", paramsFrenchHealthCard),
    ParamsListItem("Selfie", paramsSelfie),
    ParamsListItem("Address proof", paramsAddressProof),
    ParamsListItem("Vehicle registration", paramsVehicleRegistration),
    ParamsListItem("Iban", paramsIban),
    ParamsListItem("Attachment", paramsAttachment)
  ];

  void listener() {
    setState(() {
      _onboardingFolderUid = onboardingController.text;
    });
  }

  @override
  void initState() {
    super.initState();
    _dropdownMenuItems = buildDropDownMenuItems(_dropdownItems);
    _selectedItem = _dropdownMenuItems[0].value!;
    _dropdownThemeItems = buildDropDownTheme(_dropdownTheme);
    _selectedTheme = _dropdownThemeItems[0].value!;
    _onboardingListener = listener;
    onboardingController.addListener(_onboardingListener);
  }

  void dispose() {
    onboardingController.removeListener(_onboardingListener);
    super.dispose();
  }

  Future<void> activateSDK() async {
    bool activationStatus = false;
    try {
      await _idcheckioPlugin.activate(
          idToken: _activationToken,
          extractData: true);
      activationStatus = true;
    } on PlatformException catch (e) {
      activationStatus = false;
      ErrorMsg errorMsg = ErrorMsg.fromJson(jsonDecode(e.message!));
      debugPrint("An error happened during the activation : ${errorMsg.cause} - ${errorMsg.details} - ${errorMsg.message}");
    }
    if (!mounted) return;
    setState(() {
      _sdkActivated = activationStatus;
    });
  }

  Future<void> capture() async {
    IDCheckioResult? result;
    IDCheckioParamsBuilder builder = _selectedItem.params!;
    IDCheckTheme theme = _selectedTheme.theme;
    IDCheckioParams params = IDCheckioParams(builder);
    try {
      // Capture mode
      result = await _idcheckioPlugin.start(params, _captureResult?.onlineContext, theme);
      debugPrint('ID Capture Successful : ${result.toJson()}', wrapWidth: 500);
    } on PlatformException catch (e) {
      ErrorMsg errorMsg = ErrorMsg.fromJson(jsonDecode(e.message!));
      debugPrint("An error happened during the capture : ${errorMsg.cause} - ${errorMsg.message} - ${errorMsg.subCause}");
    }
    if (!mounted) return;
    setState(() {
      _captureResult = result;
    });
  }

  Future<void> startOnboarding() async {
    try {
      IDCheckTheme theme = _selectedTheme.theme;
      await _idcheckioPlugin.startOnboarding(onboardingController.text, theme);
    } on PlatformException catch (e) {
      ErrorMsg errorMsg = ErrorMsg.fromJson(jsonDecode(e.message!));
      debugPrint("An error happened during the onboarding session : ${errorMsg.cause} - ${errorMsg.message} - ${errorMsg.subCause}");
    }
  }

  List<DropdownMenuItem<ParamsListItem>> buildDropDownMenuItems(List listItems) {
    List<DropdownMenuItem<ParamsListItem>> items = [];
    for (ParamsListItem listItem in listItems as Iterable<ParamsListItem>) {
      items.add(
        DropdownMenuItem(
          child: Text(listItem.name),
          value: listItem,
        ),
      );
    }
    return items;
  }

  List<DropdownMenuItem<SdkColor>> buildDropDownTheme(List themes) {
    List<DropdownMenuItem<SdkColor>> items = [];
    for (SdkColor theme in themes as Iterable<SdkColor>) {
      items.add(
        DropdownMenuItem(
          child: Text(theme.name),
          value: theme,
        ),
      );
    }
    return items;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('IDCheck.io SDK Flutter Demo'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text(
                  getTitle(),
                  textAlign: TextAlign.center,
                  style: TextStyle(fontSize: 24.0)
              ),
              SizedBox(height: 60),
              DropdownButton(
                items: _dropdownMenuItems,
                value: _selectedItem,
                onChanged: (dynamic value) {
                  setState(() {
                    _selectedItem = value;
                  });
                },
              ),
              DropdownButton(
                items: _dropdownThemeItems,
                value: _selectedTheme,
                onChanged: (dynamic value) {
                  setState(() {
                    _selectedTheme = value;
                  });
                },
              ),
              SizedBox(height: 20),
              ElevatedButton(
                child: new Text(_sdkActivated ? "SDK already activated" : "Activate SDK"),
                onPressed: _sdkActivated ? null : activateSDK,
              ),
              Column(
                children: buildChildren(),
              ),
              SizedBox(height: 40),
              Text(
                  _captureResult != null
                      ? _captureResult!.document != null && _captureResult!.document is IdentityDocument
                      ? "Howdy ${(_captureResult!.document as IdentityDocument).fields[IdentityDocumentField.firstNames]!.value!.split(" ").first}"
                      " "
                      "${(_captureResult!.document as IdentityDocument).fields[IdentityDocumentField.lastNames]!.value}! 🤓"
                      : "Capture OK 👍"
                      : "Please first scan an ID",
                  style: TextStyle(fontSize: 20.0)),
            ],
          ),
        ),
      ),
    );
  }

  String getTitle() {
    String title;
    if(_sdkActivated && _selectedItem.isOnboarding && _onboardingFolderUid.isEmpty) {
      title = "You need to provide a folder name to start an onboarding session.";
    } else if(_sdkActivated ) {
      title = "SDK activated! 🎉";
    } else {
      title = "SDK not activated";
    }
    return title;
  }

  List<Widget> buildChildren() {
    List<Widget> builder = [];
    if(_selectedItem.isOnboarding){
      builder.add(
          Padding(
            child: TextField(
              controller: onboardingController,
              decoration: InputDecoration(
                border: OutlineInputBorder(),
                hintText: 'Enter your onboarding folder uid.',
              ),
            ),
            padding: EdgeInsets.only(left: 32.0, right: 32.0),
          )
      );
    }
    String buttonText;
    Function()? onClick;
    if(_sdkActivated && _selectedItem.isOnboarding) {
      buttonText = "Start onboarding session";
      onClick = _onboardingFolderUid.isEmpty ? null : startOnboarding;
    } else if(_sdkActivated) {
      buttonText = "Capture Document";
      onClick = capture;
    } else {
      buttonText = "SDK not activated";
      onClick = null;
    }
    builder.add(
        ElevatedButton(
          child: new Text(buttonText),
          onPressed: onClick,
        )
    );
    return builder;
  }
}
1
likes
130
pub points
30%
popularity

Publisher

verified publisheridnow.io

A flutter plugin which simplify the integration of the IDCheck.io SDK into your flutter project.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

collection, flutter, plugin_platform_interface

More

Packages that depend on idcheckio