flutter_wya_verify_sdk 1.0.0
flutter_wya_verify_sdk: ^1.0.0 copied to clipboard
WYA Verify SDK for Flutter. Identity verification with document scanning, liveness detection, and face matching. Supports iOS 13+ and Android API 21+.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:flutter_wya_verify_sdk/flutter_wya_verify_sdk.dart';
import 'dart:io' show Platform;
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _result = '';
String _sdkVersion = 'Unknown';
bool _isLoading = false;
@override
void initState() {
super.initState();
_getSdkVersion();
}
Future<void> _getSdkVersion() async {
try {
final version = await FlutterWyaVerifySdk.getSdkVersion();
setState(() => _sdkVersion = version);
} on PlatformException {
setState(() => _sdkVersion = 'Failed to get SDK version');
}
}
Future<void> _startOnboarding() async {
setState(() {
_isLoading = true;
_result = '';
});
try {
// Use environment-specific public key
final publicKey = Platform.isIOS ? 'your-ios-key' : 'your-android-key';
final result = await FlutterWyaVerifySdk.startOnboarding(
OnboardingParams(
publicKey: publicKey,
idType: 'ID',
environment: WyaEnvironment.sandbox,
),
);
setState(() {
_result = result.verified
? 'Verification successful!\n\n${_prettyJson(result.raw)}'
: 'Verification failed.\n\n${_prettyJson(result.raw)}';
});
} on WyaError catch (e) {
setState(() {
_result = 'Error: ${e.message}\nCode: ${e.code}';
});
} catch (e) {
setState(() {
_result = 'Unexpected error: $e';
});
} finally {
setState(() => _isLoading = false);
}
}
Future<void> _startFaceMatch() async {
setState(() {
_isLoading = true;
_result = '';
});
try {
final publicKey = Platform.isIOS ? 'your-ios-key' : 'your-android-key';
final result = await FlutterWyaVerifySdk.startFaceMatch(
FaceMatchParams(
publicKey: publicKey,
operationId: 'test-operation-id',
nonce: 'test-nonce',
environment: WyaEnvironment.sandbox,
),
);
setState(() {
_result = result.verified
? 'Face match successful!\n\n${_prettyJson(result.raw)}'
: 'Face match failed.\n\n${_prettyJson(result.raw)}';
});
} on WyaError catch (e) {
setState(() {
_result = 'Error: ${e.message}\nCode: ${e.code}';
});
} catch (e) {
setState(() {
_result = 'Unexpected error: $e';
});
} finally {
setState(() => _isLoading = false);
}
}
String _prettyJson(dynamic json) {
const spaces = ' ';
const encoder = JsonEncoder.withIndent(spaces);
return encoder.convert(json);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: Scaffold(
appBar: AppBar(
title: const Text('WYA Verify SDK Example'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
const Icon(Icons.verified_user, size: 48),
const SizedBox(height: 8),
Text(
'SDK Version: $_sdkVersion',
style: Theme.of(context).textTheme.titleMedium,
),
],
),
),
),
const SizedBox(height: 16),
ElevatedButton.icon(
onPressed: _isLoading ? null : _startOnboarding,
icon: const Icon(Icons.document_scanner),
label: const Text('Start Onboarding'),
),
const SizedBox(height: 8),
ElevatedButton.icon(
onPressed: _isLoading ? null : _startFaceMatch,
icon: const Icon(Icons.face),
label: const Text('Start Face Match'),
),
const SizedBox(height: 16),
if (_isLoading)
const Center(child: CircularProgressIndicator())
else if (_result.isNotEmpty)
Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: SelectableText(
_result,
style: const TextStyle(fontFamily: 'monospace'),
),
),
),
],
),
),
),
);
}
}