hyperkyc_flutter 0.2.0 copy "hyperkyc_flutter: ^0.2.0" to clipboard
hyperkyc_flutter: ^0.2.0 copied to clipboard

HyperKyc Flutter SDK can be used to create Global DKYC workflows to capture ID cards, selfie of the user, and perform face matches, etc to ease up integration friction.

example/lib/main.dart

import 'dart:convert';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hyperkyc_flutter/hyperkyc_api_result.dart';
import 'package:hyperkyc_flutter/hyperkyc_config.dart';
import 'package:hyperkyc_flutter/hyperkyc_country_result.dart';
import 'package:hyperkyc_flutter/hyperkyc_data.dart';
import 'package:hyperkyc_flutter/hyperkyc_doc_result.dart';
import 'package:hyperkyc_flutter/hyperkyc_face_result.dart';
import 'package:hyperkyc_flutter/hyperkyc_flutter.dart';
import 'package:hyperkyc_flutter/hyperkyc_form_result.dart';
import 'package:hyperkyc_flutter/hyperkyc_result.dart';
import 'package:hyperkyc_flutter/hyperkyc_webview_result.dart';
import 'package:hyperkyc_flutter_example/bloc/hyperkyc_bloc.dart';
import 'package:yaml/yaml.dart';

void main() {
  runApp(HyperKycFlutterExampleApp());
}

class HyperKycFlutterExampleApp extends StatelessWidget {
  //  TODO : Add AppId here (Get this from Hyperverge Team)
  var appId = '';

  //  TODO : Add AppKey here (Get this from Hyperverge Team)
  var appKey = '';

  //  TODO : Add AccessToken here (Get more info from Hyperverge Team)
  var accessToken = '';

  final String _chars =
      'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
  final Random _rnd = Random();

  CountryResult countryResult = CountryResult();
  List<DocResult?> docResultList = List.empty(growable: true);
  FaceResult faceResult = FaceResult();
  List<ApiResult?> apiResultList = List.empty(growable: true);
  List<FormResult?> formResultList = List.empty(growable: true);
  List<WebviewResult?> webviewResultList = List.empty(growable: true);

  HyperKycFlutterExampleApp({Key? key}) : super(key: key);

  String getRandomString(int length) => String.fromCharCodes(Iterable.generate(
      length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))));

  /// Launch AppIdAppKey HyperKyc flow when DocFace button is clicked
  void launchAppIdAppKeyHyperKyc(BuildContext context) async {
    final transactionId = 'flutter_AppIdAppKey_' + getRandomString(10);
    const workflowId = 'test_workflow_config';

    /// Reading local hyperkyc_config.yaml file to obtain appId and appKey
    // region
    final yamlString =
        await DefaultAssetBundle.of(context).loadString('hyperkyc_config.yaml');
    final dynamic hyperKycYamlMap = loadYaml(yamlString);
    appId = (hyperKycYamlMap['hyperKycAppId']);
    appKey = (hyperKycYamlMap['hyperKycAppKey']);
    // endregion

    var hyperKycConfig = HyperKycConfig.fromAppIdAppKey(
      appId: appId,
      appKey: appKey,
      workflowId: workflowId,
      transactionId: transactionId,
    );
    hyperKycConfig.setInputs(inputs: {});
    debugPrint('hyperKycConfig : $hyperKycConfig');

    HyperKycResult hyperKycResult =
        await HyperKyc.launch(hyperKycConfig: hyperKycConfig);
    BlocProvider.of<HyperkycBloc>(context)
        .add(HyperKycFinishedEvent(result: hyperKycResult));

    debugPrint('hyperKycResult : ${hyperKycResult.toString()}');
  }

  /// Launch AppIdAppKey HyperKyc flow when FaceDoc button is clicked
  void launchAccessTokenHyperKyc(BuildContext context) async {
    final transactionId = 'flutter_AccessToken_' + getRandomString(10);
    const workflowId = 'test_workflow_config';
    var hyperKycConfig = HyperKycConfig.fromAccessToken(
      accessToken: accessToken,
      workflowId: workflowId,
      transactionId: transactionId,
    );
    hyperKycConfig.setInputs(inputs: {
      'key1': 'value1',
      'key2': 'value2',
    });
    debugPrint('hyperKycConfig : $hyperKycConfig');

    HyperKycResult hyperKycResult =
        await HyperKyc.launch(hyperKycConfig: hyperKycConfig);

    BlocProvider.of<HyperkycBloc>(context)
        .add(HyperKycFinishedEvent(result: hyperKycResult));
    debugPrint('hyperKycResult : ${hyperKycResult.toString()}');
  }

  @override
  Widget build(BuildContext context) {
    return BlocProvider<HyperkycBloc>(
      create: (context) => HyperkycBloc(),
      child: MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: const Text('HyperKyc Flutter Sample'),
          ),
          body: SingleChildScrollView(
            physics: const BouncingScrollPhysics(),
            child: Column(
              children: [
                const SizedBox(
                  height: 20,
                ),
                Builder(builder: (context) {
                  return Center(
                    child: MaterialButton(
                        child: const Text('Launch AppId-AppKey HyperKyc'),
                        shape: const RoundedRectangleBorder(
                          side: BorderSide(color: Colors.blue, width: 2),
                          borderRadius: BorderRadius.all(Radius.circular(10.0)),
                        ),
                        onPressed: () {
                          BlocProvider.of<HyperkycBloc>(context)
                              .add(HyperkycLaunchedEvent());
                          launchAppIdAppKeyHyperKyc(context);
                        }),
                  );
                }),
                const SizedBox(
                  height: 30,
                ),
                Builder(builder: (context) {
                  return Center(
                    child: MaterialButton(
                      child: const Text('Launch AccessToken HyperKyc'),
                      shape: const RoundedRectangleBorder(
                        side: BorderSide(color: Colors.blue, width: 2),
                        borderRadius: BorderRadius.all(Radius.circular(10.0)),
                      ),
                      onPressed: () {
                        BlocProvider.of<HyperkycBloc>(context)
                            .add(HyperkycLaunchedEvent());
                        launchAccessTokenHyperKyc(context);
                      },
                    ),
                  );
                }),
                const Divider(
                  height: 5,
                  thickness: 2,
                ),
                Container(
                  margin: const EdgeInsets.all(10.0),
                  child: BlocConsumer<HyperkycBloc, HyperkycState>(
                    listener: (context, state) {},
                    builder: (context, state) {
                      if (state is HyperkycInitialState) {
                        return const Text('Waiting for HyperKyc to finish');
                      } else if (state is HyperkycFinishedState) {
                        Status? statusEnum = state.hyperKycResult.status;
                        String? applicationStatus =
                            state.hyperKycResult.applicationStatus;
                        HyperKycData? hyperKycData =
                            state.hyperKycResult.hyperKYCData;
                        String? reason = state.hyperKycResult.reason;

                        if (statusEnum != null) {
                          debugPrint('statusEnum : ${statusEnum.name}');
                        } else {
                          debugPrint('statusEnum is null');
                        }
                        if (hyperKycData != null) {
                          countryResult =
                              hyperKycData.countryResult ?? CountryResult();
                          String? moduleId = countryResult.moduleId;
                          String? id = countryResult.id;
                          String? name = countryResult.name;
                          String? region = countryResult.region;
                          String? baseUrl = countryResult.baseUrl;
                          debugPrint('CountryResult : $countryResult');

                          docResultList = hyperKycData.docResultList ?? [];
                          for (DocResult? docResult in docResultList) {
                            if (docResult != null) {
                              String? tag = docResult.moduleId;
                              String? documentId = docResult.documentId;

                              List<DocData?> docDataList =
                                  docResult.docDataList ?? [];
                              for (DocData? docData in docDataList) {
                                if (docData != null) {
                                  debugPrint('DocData : ');
                                  String? side = docData.side;
                                  String? docImagePath = docData.docImagePath;
                                  String? action = docData.action;
                                  String? docDataResponseHeadersJsonString =
                                      docData.responseHeaders;
                                  DocCaptureApiDetail? docDataResponseResult =
                                      docData.responseResult;

                                  debugPrint('side : $side');
                                  debugPrint('docImagePath : $docImagePath');
                                  debugPrint('action : $action');

                                  if (docDataResponseHeadersJsonString !=
                                      null) {
                                    var docDataResponseHeaders = jsonDecode(
                                        docDataResponseHeadersJsonString);
                                    debugPrint(
                                        'docDataResponseHeaders Json : ${docDataResponseHeaders.toString()}');
                                  } else {
                                    debugPrint(
                                        'docDataResponseHeadersJsonString is null');
                                  }

                                  if (docDataResponseResult != null) {
                                    debugPrint(
                                        'docDataResponseResult : ${docDataResponseResult.toString()}');
                                    if (docDataResponseResult.result != null &&
                                        docDataResponseResult.result!.details !=
                                            null &&
                                        docDataResponseResult
                                            .result!.details!.isNotEmpty) {
                                      for (var detail in docDataResponseResult
                                          .result!.details!) {
                                        debugPrint(
                                            'ocr fullname : ${detail?.fieldsExtracted?.fullName?.value}');
                                      }
                                    }
                                  } else {
                                    debugPrint('docDataResponseResult is null');
                                  }
                                } else {
                                  debugPrint('docData is null');
                                }
                              }
                            } else {
                              debugPrint('docResult is null');
                            }
                          }

                          faceResult = hyperKycData.faceResult ?? FaceResult();
                          FaceData? faceData = faceResult.faceData;
                          if (faceData != null) {
                            String? croppedFaceImagePath =
                                faceData.croppedFaceImagePath;
                            String? fullFaceImagePath =
                                faceData.fullFaceImagePath;
                            String? videoPath = faceData.videoPath;
                            String? action = faceData.action;
                            String? faceDataResponseHeadersJsonString =
                                faceData.responseHeaders;
                            FaceCaptureApiDetail? faceDataResponseResult =
                                faceData.responseResult;

                            debugPrint(
                                'croppedFaceImagePath : $croppedFaceImagePath');
                            debugPrint(
                                'fullFaceImagePath : $fullFaceImagePath');
                            debugPrint('videoPath : $videoPath');
                            debugPrint('action : $action');

                            if (faceDataResponseHeadersJsonString != null) {
                              var faceDataResponseHeaders =
                                  jsonDecode(faceDataResponseHeadersJsonString);

                              debugPrint(
                                  'faceDataResponseHeaders Json : ${faceDataResponseHeaders.toString()}');
                            } else {
                              debugPrint('faceDataResponseHeaders is null');
                            }

                            if (faceDataResponseResult != null) {
                              debugPrint(
                                  'faceDataResponseResult : ${faceDataResponseResult.toString()}');
                              debugPrint(
                                  'faceLive : ${faceDataResponseResult.result?.details?.liveFace}');
                            } else {
                              debugPrint('faceDataResponseResult is null');
                            }
                            debugPrint(
                                'faceDataResponseResult Json : ${faceDataResponseResult.toString()}');
                          } else {
                            debugPrint('faceData is null');
                          }

                          apiResultList = hyperKycData.apiResultList ?? [];
                          for (ApiResult? apiResult in apiResultList) {
                            if (apiResult != null) {
                              String? tag = apiResult.moduleId;

                              ApiData apiData = apiResult.apiData ?? ApiData();
                              debugPrint('ApiData : $apiData');
                            } else {
                              debugPrint('apiResult is null');
                            }
                          }

                          formResultList = hyperKycData.formResultList ?? [];
                          for (FormResult? formResult in formResultList) {
                            if (formResult != null) {
                              String? tag = formResult.moduleId;
                            } else {
                              debugPrint('formResult is null');
                            }
                          }

                          webviewResultList =
                              hyperKycData.webviewResultList ?? [];
                          for (WebviewResult? webviewResult
                              in webviewResultList) {
                            if (webviewResult != null) {
                              String? tag = webviewResult.moduleId;

                              WebviewData webviewData =
                                  webviewResult.webviewData ?? WebviewData();
                              debugPrint('WebviewData : $webviewData');
                            } else {
                              debugPrint('webviewResult is null');
                            }
                          }
                        } else {
                          debugPrint('hyperKycData is null');
                        }

                        if (reason != null) {
                          debugPrint('errorMessage : $reason');
                        } else {
                          debugPrint('errorMessage is null');
                        }

                        return Column(
                          children: [
                            const Text(
                              'HyperKycResult',
                              style: TextStyle(
                                fontWeight: FontWeight.bold,
                                fontSize: 18,
                              ),
                            ),
                            Column(
                              children: [
                                Text('Status : $statusEnum'),
                                const Divider(
                                  height: 2,
                                  thickness: 2,
                                ),
                                Text('ApplicationStatus : $applicationStatus'),
                                const Divider(
                                  height: 2,
                                  thickness: 2,
                                ),
                                const Text('HyperKycData'),
                                Column(
                                  children: [
                                    Text(
                                        'CountryResult : ${countryResult.toString()}'),
                                    const Divider(
                                      height: 2,
                                      thickness: 2,
                                    ),
                                    // Text(
                                    //     'Selected document : $selectedDocument'),
                                    const Divider(
                                      height: 2,
                                      thickness: 2,
                                    ),
                                    docResultList.isNotEmpty
                                        ? Text('DocResultList : $docResultList')
                                        : const Text('DocResultList is empty'),
                                    const Divider(
                                      height: 2,
                                      thickness: 2,
                                    ),
                                    Text(
                                        'FaceResult : ${faceResult.toString()}'),
                                    const Divider(
                                      height: 2,
                                      thickness: 2,
                                    ),
                                    apiResultList.isNotEmpty
                                        ? Text('APIResultList : $apiResultList')
                                        : const Text('APIResultList is empty'),
                                    const Divider(
                                      height: 2,
                                      thickness: 2,
                                    ),
                                    formResultList.isNotEmpty
                                        ? Text(
                                            'FormResultList : $formResultList')
                                        : const Text('FormResultList is empty'),
                                    const Divider(
                                      height: 2,
                                      thickness: 2,
                                    ),
                                    webviewResultList.isNotEmpty
                                        ? Text(
                                            'WebviewResultList : $webviewResultList')
                                        : const Text(
                                            'WebviewResultList is empty'),
                                  ],
                                ),
                                const Divider(
                                  height: 2,
                                  thickness: 2,
                                ),
                                Text('Reason: $reason'),
                              ],
                            ),
                          ],
                        );
                      } else {
                        return const Text('This case has not been added');
                      }
                    },
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
7
likes
0
pub points
92%
popularity

Publisher

unverified uploader

HyperKyc Flutter SDK can be used to create Global DKYC workflows to capture ID cards, selfie of the user, and perform face matches, etc to ease up integration friction.

Homepage

License

unknown (LICENSE)

Dependencies

flutter, test

More

Packages that depend on hyperkyc_flutter