hyperkyc_flutter 0.36.0
hyperkyc_flutter: ^0.36.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: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_flutter.dart';
import 'package:hyperkyc_flutter/hyperkyc_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 = '';
// TODO : Add relevant workflowId here (Get more info from Hyperverge Team)
var workflowId = 'twc_demo';
final String _chars =
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
final Random _rnd = Random();
HyperKycFlutterExampleApp({Key? key}) : super(key: key);
String getRandomString(int length) => String.fromCharCodes(Iterable.generate(
length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))));
/// Prefetches configs
void prefetch(BuildContext context) async {
/// 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
HyperKyc.prefetch(
appId: appId,
workflowId: workflowId,
);
}
/// Launch AppIdAppKey HyperKyc flow
void launchAppIdAppKeyHyperKyc(BuildContext context) async {
final transactionId = 'flutter_AppIdAppKey_' + getRandomString(10);
/// 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
void launchAccessTokenHyperKyc(BuildContext context) async {
final transactionId = 'flutter_AccessToken_' + getRandomString(10);
/// Reading local hyperkyc_config.yaml file to obtain accessToken
// region
final yamlString =
await DefaultAssetBundle.of(context).loadString('hyperkyc_config.yaml');
final dynamic hyperKycYamlMap = loadYaml(yamlString);
accessToken = (hyperKycYamlMap['hyperKycAccessToken']);
// endregion
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('Prefetch'),
shape: const RoundedRectangleBorder(
side: BorderSide(color: Colors.blue, width: 2),
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
onPressed: () {
prefetch(context);
}),
);
}),
const SizedBox(
height: 30,
),
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) {
debugPrint('hyperKycResult : ${state.hyperKycResult}');
String? status = state.hyperKycResult.status?.value;
String? transactionId =
state.hyperKycResult.transactionId;
Map<dynamic, dynamic>? details =
state.hyperKycResult.details;
int? errorCode = state.hyperKycResult.errorCode;
String? errorMessage =
state.hyperKycResult.errorMessage;
String? latestModule =
state.hyperKycResult.latestModule;
return Column(
children: [
const Text(
'HyperKycResult',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
Column(
children: [
Text('Status : $status'),
const Divider(
height: 2,
thickness: 2,
),
Text('TransactionId : $transactionId'),
const Divider(
height: 2,
thickness: 2,
),
Text('Details : ${details.toString()}'),
const Divider(
height: 2,
thickness: 2,
),
Text('ErrorCode : ${errorCode.toString()}'),
const Divider(
height: 2,
thickness: 2,
),
Text('ErrorMessage : $errorMessage'),
const Divider(
height: 2,
thickness: 2,
),
Text('LatestModule : $latestModule'),
],
),
],
);
} else {
return const Text('This case has not been added');
}
},
),
),
],
),
),
),
),
);
}
}