idflow_myid 1.0.5
idflow_myid: ^1.0.5 copied to clipboard
IDFlow SDK plugin for Flutter. Package supports iOS and Android to verify users identity.
example/lib/main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:idflow_myid/idflow_config.dart';
import 'package:idflow_myid/idflow_enums.dart';
import 'package:idflow_myid/idflow_myid.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String? _error;
IDFlowResult? _result;
IDFlowEntryMode _entryMode = IDFlowEntryMode.documentOnly;
bool _isResident = true;
bool _documentEditEnabled = false;
bool _useActiveLiveness = false;
bool _showSelfiePreview = true;
// 1x1 transparent PNG, used only to demonstrate infoImageBase64 wiring.
static const _sampleInfoImageBase64 =
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=';
Future<void> init() async {
String? error;
IDFlowResult? result;
try {
final idflowResult = await IDFlowClient.start(
config: IDFlowConfig(
entryMode: _entryMode,
locale: IDFlowLocale.kyrgyz,
presentationStyle: IDFlowPresentationStyle.full,
previewConfig: IDFlowPreviewConfig(
showSelfiePreview: _showSelfiePreview,
),
documentConfig: IDFlowDocumentConfig(
isResident: _isResident,
documentEditEnabled: _documentEditEnabled,
timeoutSeconds: 180,
),
videoConfig: const IDFlowVideoConfig(
videoFilePath: '/data/local/tmp/idflow_video.mp4',
),
faceConfig: IDFlowFaceConfig(useActiveLiveness: _useActiveLiveness),
activeLivenessConfig: const IDFlowActiveLivenessConfig(
uiVariant: IDFlowActiveLivenessUiVariant.variant1,
challengeTimeoutMs: 15000,
),
),
iosAppearance: const IDFlowIOSAppearance(
face: IDFlowIOSFaceAppearance(
infoImageBase64: _sampleInfoImageBase64,
),
),
);
error = null;
result = idflowResult;
} catch (e) {
error = e.toString();
result = null;
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_error = error;
_result = result;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('IDFlow Sample'),
),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
DropdownButton<IDFlowEntryMode>(
value: _entryMode,
isExpanded: true,
items: IDFlowEntryMode.values
.map((mode) => DropdownMenuItem(
value: mode,
child: Text(mode.name),
))
.toList(),
onChanged: (mode) {
if (mode != null) setState(() => _entryMode = mode);
},
),
SwitchListTile(
title: const Text('isResident'),
value: _isResident,
onChanged: (value) => setState(() => _isResident = value),
),
SwitchListTile(
title: const Text('documentEditEnabled'),
value: _documentEditEnabled,
onChanged: (value) => setState(() => _documentEditEnabled = value),
),
SwitchListTile(
title: const Text('useActiveLiveness'),
value: _useActiveLiveness,
onChanged: (value) => setState(() => _useActiveLiveness = value),
),
SwitchListTile(
title: const Text('showSelfiePreview'),
value: _showSelfiePreview,
onChanged: (value) => setState(() => _showSelfiePreview = value),
),
MaterialButton(
color: Theme.of(context).colorScheme.primary,
textColor: Colors.white,
onPressed: init,
child: const Text('Start SDK'),
),
const SizedBox(height: 16),
if (_error != null) Text(_error!),
if (_result != null) ..._buildResult(_result!),
],
),
),
);
}
List<Widget> _buildResult(IDFlowResult result) {
return [
Text('personalNumber: ${result.personalNumber ?? ''}'),
Text('idSeriesNumber: ${result.idSeriesNumber ?? ''}'),
const SizedBox(height: 12),
const Text('Document result:'),
..._buildDocumentResult(result.documentResult),
const SizedBox(height: 12),
const Text('Editable document result:'),
..._buildDocumentResult(result.editableDocumentResult),
];
}
List<Widget> _buildDocumentResult(IDFlowDocumentResult? document) {
final fields = {
'pinfl': document?.pinfl,
'document': document?.document,
'lastName': document?.lastName,
'firstName': document?.firstName,
'birthDate': document?.birthDate,
'expiryDate': document?.expiryDate,
'countryCode': document?.countryCode,
'issueDate': document?.issueDate,
'issuedBy': document?.issuedBy,
'mrz': document?.mrz,
};
return fields.entries
.map((field) => Text('${field.key}: ${field.value ?? ''}'))
.toList();
}
}