hyperkyc_flutter 0.0.2
hyperkyc_flutter: ^0.0.2 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 AccessToken here (Get more info from Hyperverge Team)
final accessToken = '';
final String _chars =
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
final Random _rnd = Random();
String selectedCountry = '';
String selectedDocument = '';
List<DocData?> docDataList = List.empty(growable: true);
FaceData faceData = FaceData();
FaceMatchData faceMatchData = FaceMatchData();
MyApp({Key? key}) : super(key: key);
String getRandomString(int length) => String.fromCharCodes(Iterable.generate(
length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))));
/// Launch DocFace HyperKyc flow when DocFace button is clicked
void launchDocFaceHyperKyc(BuildContext context) async {
final transactionId = "flutter_docface_" + getRandomString(10);
var hyperKycConfig = HyperKycConfigBuilder()
.setAppId(appId: appId)
.setAccessToken(accessToken: accessToken)
.setTransactionId(transactionId: transactionId)
.setWorkFlow(
workFlow: [
HyperKycFlow.document,
HyperKycFlow.face,
],
).build();
HyperKycResult hyperKycResult =
await HyperKyc.launch(hyperKycConfig: hyperKycConfig);
BlocProvider.of<HyperkycBloc>(context)
.add(HyperKycFinishedEvent(result: hyperKycResult));
debugPrint('hyperKycResult : ${hyperKycResult.toString()}');
}
/// Launch FaceDoc HyperKyc flow when FaceDoc button is clicked
void launchFaceDocHyperKyc(BuildContext context) async {
final transactionId = "flutter_facedoc_" + getRandomString(10);
var hyperKycConfig = HyperKycConfigBuilder()
.setAppId(appId: appId)
.setAccessToken(accessToken: accessToken)
.setTransactionId(transactionId: transactionId)
.setWorkFlow(
workFlow: [
HyperKycFlow.face,
HyperKycFlow.document,
],
).build();
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 Doc Face 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());
launchDocFaceHyperKyc(context);
}),
);
}),
const SizedBox(
height: 30,
),
Builder(builder: (context) {
return Center(
child: MaterialButton(
child: const Text('Launch Face Doc 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());
launchFaceDocHyperKyc(context);
},
),
);
}),
const Divider(
height: 5,
thickness: 2,
),
Container(
margin: const EdgeInsets.all(10.0),
child: BlocConsumer<HyperkycBloc, HyperkycState>(
listener: (context, state) {
// TODO: implement listener
},
builder: (context, state) {
if (state is HyperkycInitialState) {
return const Text('Waiting for HyperKyc to finish');
} else if (state is HyperkycFinishedState) {
HyperKycResultEnum? resultEnum =
state.hyperKycResult.result;
HyperKycData? hyperKycData =
state.hyperKycResult.hyperKYCData;
String? errorMessage =
state.hyperKycResult.errorMessage;
if (resultEnum != null) {
debugPrint('resultEnum : ${resultEnum.name}');
} else {
debugPrint('resultEnum is null');
}
if (hyperKycData != null) {
selectedCountry = hyperKycData.selectedCountry ?? '';
selectedDocument =
hyperKycData.selectedDocument ?? '';
docDataList = hyperKycData.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');
}
}
}
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');
}
faceMatchData =
hyperKycData.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('hyperKycData is null');
}
if (errorMessage != null) {
debugPrint('errorMessage : $errorMessage');
} else {
debugPrint('errorMessage is null');
}
return Column(
children: [
const Text(
'HyperKycResult',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
Column(
children: [
Text('Result : $resultEnum'),
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,
),
docDataList.isNotEmpty
? Text('DocData : $docDataList')
: Container(),
const Divider(
height: 2,
thickness: 2,
),
faceData != null
? Text(
'FaceData : ${faceData.toString()}')
: Container(),
const Divider(
height: 2,
thickness: 2,
),
faceMatchData != null
? Text(
'FaceMatchData : ${faceMatchData.toString()}')
: Container(),
],
),
const Divider(
height: 2,
thickness: 2,
),
Text('ErrorMessage: $errorMessage'),
],
),
],
);
} else {
return const Text('This case has not been added');
}
},
),
),
],
),
),
),
),
);
}
}