sdk_pfl_flutter 4.7.0
sdk_pfl_flutter: ^4.7.0 copied to clipboard
A flutter plugin for the Au10tix Passive Face Liveness module SDK
example/lib/main.dart
// ignore_for_file: use_key_in_widget_constructors
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sdk_core_flutter/sdk_core_flutter.dart';
import 'package:sdk_pfl_flutter/sdk_pfl_flutter.dart';
import 'package:sdk_pfl_flutter_example/constants.dart';
import 'pfl_page.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Au10tix Flutter PFL Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
routes: {
PFLPage.routeName: (ctx) => PFLPage(),
},
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
String _authToken = "";
bool _enableMicrophone = true;
bool suspiciousBehavior = false;
Future<void> _prepareSDK(BuildContext context) async {
try {
_authToken = workflowResponse;
final result = await Au10tix.init(_authToken);
if (result.containsKey("init")) {
_showToast(context, result["init"].toString(), Colors.green);
}
} on PlatformException catch (error) {
_showToast(context, error.message!, Colors.red);
// ignore: empty_catches
} catch (error) {}
}
Future<void> _startPFLUI() async {
try {
//UI config is optional
UIConfig uiConfig = UIConfig(
showIntroScreen: true,
showCloseButton: true,
showPrimaryButton: true);
// Create suspicious behavior config if enabled
SuspiciousBehaviorConfig? suspiciousBehaviorConfig;
if (suspiciousBehavior) {
suspiciousBehaviorConfig = const SuspiciousBehaviorConfig();
}
final result = await SdkPflFlutter.startPFLUI(
uiConfig: uiConfig,
isF2F: true,
enableMicrophone: _enableMicrophone,
suspiciousBehaviorConfig: suspiciousBehaviorConfig);
if (kDebugMode) {
print(result.toString());
}
} on PlatformException catch (error) {
if (kDebugMode) {
print(error.message);
}
}
}
Future<void> _sendWorkflowRequest(BuildContext context) async {
// Always let user choose an image from gallery
final imagePath = await Au10tix.getImageFromGallery();
if (imagePath == null) {
// User cancelled image selection
return;
}
try {
if (kDebugMode) {
print('Selected image path: $imagePath');
}
// Type 34: updatePhotoForComparison
final photoResult = await Au10tix.updatePhotoForComparison(imagePath);
if (kDebugMode) {
print('Photo update result: $photoResult');
}
_showToast(context, 'Photo updated for comparison', Colors.blue);
final result = await Au10tix.sendWorkflowRequest();
if (result.containsKey("beKit")) {
_showToast(
context, result["beKit"]["message"].toString(), Colors.green);
}
} on PlatformException catch (error) {
_showToast(context, error.message!, Colors.red);
// ignore: empty_catches
} catch (error) {}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin pfl example app'),
),
body: Column(
children: [
// Microphone Toggle
Card(
margin: const EdgeInsets.all(16.0),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
_enableMicrophone ? Icons.mic : Icons.mic_off,
color: _enableMicrophone ? Colors.green : Colors.red,
),
const SizedBox(width: 8),
Text(
'Enable Microphone',
style: Theme.of(context).textTheme.titleMedium,
),
],
),
Switch(
value: _enableMicrophone,
onChanged: (bool value) {
setState(() {
_enableMicrophone = value;
});
},
),
],
),
),
),
// Suspicious Behavior Toggle
Card(
margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
suspiciousBehavior ? Icons.security : Icons.security_outlined,
color: suspiciousBehavior ? Colors.orange : Colors.grey,
),
const SizedBox(width: 8),
Text(
'Suspicious Behavior Detection',
style: Theme.of(context).textTheme.titleMedium,
),
],
),
Switch(
value: suspiciousBehavior,
onChanged: (bool value) {
setState(() {
suspiciousBehavior = value;
});
},
),
],
),
),
),
// Main content area
Expanded(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => _prepareSDK(context),
child: const Text("Prepare SDK"),
),
ElevatedButton(
onPressed: () {
SuspiciousBehaviorConfig? config;
if (suspiciousBehavior) {
// Use platform-specific configuration
if (Platform.isIOS) {
config = SuspiciousBehaviorConfig.forIOS();
} else if (Platform.isAndroid) {
config = SuspiciousBehaviorConfig.forAndroid();
} else {
config = const SuspiciousBehaviorConfig();
}
}
Navigator.of(context).pushNamed(
PFLPage.routeName,
arguments: {
'isF2F': true,
'enableMicrophone': _enableMicrophone,
'suspiciousBehaviorConfig': config
});
},
child: const Text("Start PFL"),
),
ElevatedButton(
onPressed: () => _startPFLUI(),
child: const Text("Start PFL UI"),
),
ElevatedButton(
onPressed: () => _sendWorkflowRequest(context),
child: const Text("Send Workflow F2F/34 Request"),
),
],
),
),
),
],
),
);
}
void _showToast(BuildContext context, String message, Color bgColor) {
final scaffold = ScaffoldMessenger.of(context);
scaffold.showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: bgColor,
),
);
}
}