hyperkyc_flutter 0.0.5
hyperkyc_flutter: ^0.0.5 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_config.dart';
import 'package:hyperkyc_flutter/hyperkyc_data.dart';
import 'package:hyperkyc_flutter/hyperkyc_doc_data.dart';
import 'package:hyperkyc_flutter/hyperkyc_face_data.dart';
import 'package:hyperkyc_flutter/hyperkyc_face_match_data.dart';
import 'package:hyperkyc_flutter/hyperkyc_flutter.dart';
import 'package:hyperkyc_flutter/hyperkyc_result.dart';
import 'package:hyperkyc_flutter_example/bloc/hyperkyc_bloc.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// TODO : Add AppId here (Get this from Hyperverge Team)
final appId = '';
// TODO : Add AppKey here (Get this from Hyperverge Team)
final appKey = '';
// TODO : Add AccessToken here (Get more info from Hyperverge Team)
final accessToken = '';
final String _chars =
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
final Random _rnd = Random();
String selectedCountry = '';
List<DocResult?> docResultList = List.empty(growable: true);
FaceData faceData = FaceData();
List<FaceMatchDataResult?> faceMatchDataResultList =
List.empty(growable: true);
MyApp({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);
final workflow = [
{
'type': 'face',
},
{
'type': 'document',
'useForFaceMatch': true,
},
{
'type': 'document',
'countryId': 'usa',
'documentId': 'passport',
'useForFaceMatch': false,
},
];
var hyperKycConfig = HyperKycConfig.fromAppIdAppKey(
appId: appId,
appKey: appKey,
transactionId: transactionId,
workFlow: workflow,
defaultCountryId: 'ind',
);
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);
final workflow = [
{
'type': 'document',
'countryId': 'ind',
'documentId': 'pan',
'useForFaceMatch': false,
},
{
'type': 'face',
},
{
'type': 'document',
'useForFaceMatch': true,
},
];
var hyperKycConfig = HyperKycConfig.fromAccessToken(
accessToken: accessToken,
transactionId: transactionId,
workFlow: workflow,
);
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;
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) {
selectedCountry = hyperKycData.selectedCountry ?? '';
docResultList = hyperKycData.docResultList ?? [];
for (DocResult? docResult in docResultList) {
if (docResult != null) {
String? tag = docResult.tag;
String? documentId = docResult.documentId;
List<DocData?> docDataList =
docResult.docDataList ?? [];
if (docDataList != null) {
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');
}
}
faceData = hyperKycData.faceData ?? 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');
}
faceMatchDataResultList =
hyperKycData.faceMatchDataResultList ?? [];
for (FaceMatchDataResult? faceMatchDataResult
in faceMatchDataResultList) {
if (faceMatchDataResult != null) {
String? tag = faceMatchDataResult.tag;
String? documentId =
faceMatchDataResult.documentId;
FaceMatchData faceMatchData =
faceMatchDataResult.faceMatchData ??
FaceMatchData();
if (faceMatchData != null) {
String? action = faceMatchData.action;
String? faceMatchDataResponseHeadersJsonString =
faceMatchData.responseHeaders;
FaceMatchApiDetail?
faceMatchDataResponseResult =
faceMatchData.responseResult;
debugPrint('action : $action');
if (faceMatchDataResponseHeadersJsonString !=
null) {
var faceMatchDataResponseHeaders = jsonDecode(
faceMatchDataResponseHeadersJsonString);
debugPrint(
'faceMatchDataResponseHeaders Json : ${faceMatchDataResponseHeaders.toString()}');
} else {
debugPrint(
'faceMatchDataResponseHeadersJsonString is null');
}
if (faceMatchDataResponseResult != null) {
debugPrint(
'faceMatchDataResponseResult : ${faceMatchDataResponseResult.toString()}');
debugPrint(
'faceMatch : ${faceMatchDataResponseResult.result?.details?.match}');
} else {
debugPrint(
'faceMatchDataResponseResult is null');
}
} else {
debugPrint('faceMatchData is null');
}
} else {
debugPrint('faceMatchDataResult 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,
),
const Text('HyperKycData'),
Column(
children: [
Text('Selected country : $selectedCountry'),
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,
),
faceData != null
? Text(
'FaceData : ${faceData.toString()}')
: Container(),
const Divider(
height: 2,
thickness: 2,
),
faceMatchDataResultList.isNotEmpty
? Text(
'FaceMatchDataResultList : $faceMatchDataResultList')
: const Text(
'FaceMatchDataResultList is empty'),
],
),
const Divider(
height: 2,
thickness: 2,
),
Text('Reason: $reason'),
],
),
],
);
} else {
return const Text('This case has not been added');
}
},
),
),
],
),
),
),
),
);
}
}