sdk_vc_flutter 4.7.1
sdk_vc_flutter: ^4.7.1 copied to clipboard
A flutter plugin for the Au10tix Voice Consent module SDK
example/lib/main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:sdk_vc_flutter/sdk_vc_flutter.dart';
import 'package:sdk_core_flutter/sdk_core_flutter.dart';
import 'constants.dart';
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> {
final GlobalKey<ScaffoldMessengerState> _scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
// Voice Consent settings
final _vcConsentTextController = TextEditingController(
text: 'I agree to provide my voice consent for verification purposes.',
);
double _vcSessionDuration = 20.0;
bool _vcShowConsent = false;
// Video Session settings
final _vsConsentTextController = TextEditingController(
text: 'I consent to this video session for verification purposes.',
);
bool _vsShowConsent = false;
double _vsSelfieDuration = 7.0;
double _vsIdDuration = 5.0;
// ID Thickness settings
final _idtConsentTextController = TextEditingController(
text: 'I consent to capture images of my ID for thickness verification.',
);
bool _idtShowConsent = false;
double _idtFrontDuration = 8.0;
double _idtBackDuration = 8.0;
double _idtTiltedDuration = 8.0;
double _idtInstructionsDuration = 3.0;
@override
void initState() {
super.initState();
}
Future<void> _prepareSDK() async {
try {
final result = await Au10tix.init(workflowResponse);
if (!mounted) return;
if (result.containsKey("init")) {
_showToast('Session Prepared Successfully', Colors.green);
} else {
_showToast('SDK Initialized', Colors.green);
}
} on PlatformException catch (error) {
if (!mounted) return;
_showToast(error.message ?? 'SDK Preparation Error', Colors.red);
}
}
Future<void> _startVCUI() async {
try {
if (kDebugMode) {
print('Voice Consent Config:');
print('- Consent Text: ${_vcConsentTextController.text}');
print('- Session Duration: $_vcSessionDuration seconds');
}
final result = await SdkVcFlutter.startVCUI(
vcSessionTime: _vcSessionDuration,
consentText: _vcConsentTextController.text,
showConsent: _vcShowConsent,
);
if (!mounted) return;
if (result is Map && result.containsKey('vc')) {
final videoPath = result['vc']['videoPath'];
_showToast('Voice Consent Completed: $videoPath', Colors.green);
if (kDebugMode) {
print('VC Result: $result');
}
}
} on PlatformException catch (error) {
if (!mounted) return;
_showToast(error.message ?? 'Voice Consent Error', Colors.red);
}
}
Future<void> _startVideoSession() async {
try {
if (kDebugMode) {
print('Video Session Config:');
print('- Consent Text: ${_vsConsentTextController.text}');
print('- Selfie Duration: $_vsSelfieDuration seconds');
print('- ID Duration: $_vsIdDuration seconds');
}
final result = await SdkVcFlutter.startVideoSession(
consentText: _vsConsentTextController.text,
showConsent: _vsShowConsent,
selfieDuration: _vsSelfieDuration,
idDuration: _vsIdDuration,
);
if (!mounted) return;
if (result is Map && result.containsKey('vc')) {
final videoPath = result['vc']['videoPath'] ?? 'No video path';
_showToast('Video Session Completed: $videoPath', Colors.green);
if (kDebugMode) {
print('Video Session Result: $result');
}
}
} on PlatformException catch (error) {
if (!mounted) return;
_showToast(error.message ?? 'Video Session Error', Colors.red);
}
}
Future<void> _startIDThickness() async {
try {
if (kDebugMode) {
print('ID Thickness Config:');
print('- Consent Text: ${_idtConsentTextController.text}');
print('- Show Consent: $_idtShowConsent');
print('- Front Duration: $_idtFrontDuration seconds');
print('- Back Duration: $_idtBackDuration seconds');
print('- Tilted Duration: $_idtTiltedDuration seconds');
print('- Instructions Duration: $_idtInstructionsDuration seconds');
}
final result = await SdkVcFlutter.startIDThickness(
consentText: _idtConsentTextController.text,
showConsent: _idtShowConsent,
frontDuration: _idtFrontDuration,
backDuration: _idtBackDuration,
tiltedDuration: _idtTiltedDuration,
instructionsDuration: _idtInstructionsDuration,
);
if (!mounted) return;
if (result is Map && result.containsKey('vc')) {
final videoPath = result['vc']['videoPath'] ?? 'No video path';
_showToast('ID Thickness Completed: $videoPath', Colors.orange);
if (kDebugMode) {
print('ID Thickness Result: $result');
}
}
} on PlatformException catch (error) {
if (!mounted) return;
_showToast(error.message ?? 'ID Thickness Error', Colors.red);
}
}
@override
void dispose() {
_vcConsentTextController.dispose();
_vsConsentTextController.dispose();
_idtConsentTextController.dispose();
super.dispose();
}
void _showToast(String message, Color bgColor) {
_scaffoldMessengerKey.currentState?.showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: bgColor,
duration: const Duration(seconds: 3),
),
);
if (kDebugMode) {
print('Toast: $message');
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
scaffoldMessengerKey: _scaffoldMessengerKey,
home: Scaffold(
appBar: AppBar(
title: const Text('Au10tix SDK Demo'),
),
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: _prepareSDK,
child: const Text('Prepare SDK'),
),
const SizedBox(height: 20),
// Voice Consent Settings
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border.all(color: Colors.blue),
borderRadius: BorderRadius.circular(8),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Voice Consent Settings',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
),
const SizedBox(height: 16),
TextField(
controller: _vcConsentTextController,
decoration: const InputDecoration(
labelText: 'Consent Text',
border: OutlineInputBorder(),
),
maxLines: 3,
),
const SizedBox(height: 16),
SwitchListTile(
title: const Text('Show Consent'),
value: _vcShowConsent,
dense: true,
activeColor: Colors.blue,
onChanged: (value) {
setState(() {
_vcShowConsent = value;
});
},
),
const SizedBox(height: 8),
Text('Session Duration: ${_vcSessionDuration.toInt()} seconds (5-30)'),
Slider(
value: _vcSessionDuration,
min: 5.0,
max: 30.0,
divisions: 25,
label: '${_vcSessionDuration.toInt()}s',
activeColor: Colors.blue,
onChanged: (value) {
setState(() {
_vcSessionDuration = value;
});
},
),
],
),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: _startVCUI,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
minimumSize: const Size(200, 50),
),
child: const Text('Start Voice Consent'),
),
const SizedBox(height: 20),
// Video Session Settings
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border.all(color: Colors.green),
borderRadius: BorderRadius.circular(8),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Video Session Settings',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.green,
),
),
const SizedBox(height: 16),
TextField(
controller: _vsConsentTextController,
decoration: const InputDecoration(
labelText: 'Consent Text',
border: OutlineInputBorder(),
),
maxLines: 2,
),
const SizedBox(height: 16),
SwitchListTile(
title: const Text('Show Consent'),
value: _vsShowConsent,
dense: true,
activeColor: Colors.green,
onChanged: (value) {
setState(() {
_vsShowConsent = value;
});
},
),
const SizedBox(height: 8),
Text('Selfie Duration: ${_vsSelfieDuration.toInt()} seconds (4-30)'),
Slider(
value: _vsSelfieDuration,
min: 4.0,
max: 30.0,
divisions: 26,
label: '${_vsSelfieDuration.toInt()}s',
activeColor: Colors.green,
onChanged: (value) {
setState(() {
_vsSelfieDuration = value;
});
},
),
const SizedBox(height: 8),
Text('ID Duration: ${_vsIdDuration.toInt()} seconds (4-30)'),
Slider(
value: _vsIdDuration,
min: 4.0,
max: 30.0,
divisions: 26,
label: '${_vsIdDuration.toInt()}s',
activeColor: Colors.green,
onChanged: (value) {
setState(() {
_vsIdDuration = value;
});
},
),
],
),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: _startVideoSession,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
minimumSize: const Size(200, 50),
),
child: const Text('Start Video Session'),
),
const SizedBox(height: 20),
// ID Thickness Settings
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border.all(color: Colors.orange),
borderRadius: BorderRadius.circular(8),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'ID Thickness Settings',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.orange,
),
),
const SizedBox(height: 16),
TextField(
controller: _idtConsentTextController,
decoration: const InputDecoration(
labelText: 'Consent Text',
border: OutlineInputBorder(),
),
maxLines: 2,
),
const SizedBox(height: 16),
SwitchListTile(
title: const Text('Show Consent'),
value: _idtShowConsent,
dense: true,
activeColor: Colors.orange,
onChanged: (value) {
setState(() {
_idtShowConsent = value;
});
},
),
const SizedBox(height: 8),
Text('Front Duration: ${_idtFrontDuration.toInt()} seconds (1-15)'),
Slider(
value: _idtFrontDuration,
min: 1.0,
max: 15.0,
divisions: 14,
label: '${_idtFrontDuration.toInt()}s',
activeColor: Colors.orange,
onChanged: (value) {
setState(() {
_idtFrontDuration = value;
});
},
),
const SizedBox(height: 8),
Text('Back Duration: ${_idtBackDuration.toInt()} seconds (1-15)'),
Slider(
value: _idtBackDuration,
min: 1.0,
max: 15.0,
divisions: 14,
label: '${_idtBackDuration.toInt()}s',
activeColor: Colors.orange,
onChanged: (value) {
setState(() {
_idtBackDuration = value;
});
},
),
const SizedBox(height: 8),
Text('Tilted Duration: ${_idtTiltedDuration.toInt()} seconds (1-15)'),
Slider(
value: _idtTiltedDuration,
min: 1.0,
max: 15.0,
divisions: 14,
label: '${_idtTiltedDuration.toInt()}s',
activeColor: Colors.orange,
onChanged: (value) {
setState(() {
_idtTiltedDuration = value;
});
},
),
const SizedBox(height: 8),
Text('Instructions Duration: ${_idtInstructionsDuration.toInt()} seconds (1-6)'),
Slider(
value: _idtInstructionsDuration,
min: 1.0,
max: 6.0,
divisions: 5,
label: '${_idtInstructionsDuration.toInt()}s',
activeColor: Colors.orange,
onChanged: (value) {
setState(() {
_idtInstructionsDuration = value;
});
},
),
],
),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: _startIDThickness,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
minimumSize: const Size(200, 50),
),
child: const Text('Start ID Thickness'),
),
const SizedBox(height: 20),
],
),
),
),
),
);
}
}