new_face_authenticator 1.1.1 new_face_authenticator: ^1.1.1 copied to clipboard
Flutter plugin cross-platform (iOS, Android) for Combate à Fraude's FaceAuthenticator (https://github.com/combateafraude).
import 'package:new_face_authenticator/caf_stage.dart';
import 'package:new_face_authenticator/face_authenticator.dart';
import 'package:new_face_authenticator/result/face_authenticator_failure.dart';
import 'package:new_face_authenticator/result/face_authenticator_result.dart';
import 'package:new_face_authenticator/result/face_authenticator_success.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:permission_handler/permission_handler.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _result = "";
String _description = "";
String mobileToken =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI1ZjA5ZmJmNzdiMWFlZTAwMDdhMjFjYzIifQ.wHK8KPA00Q-Ue8KM26hWXJuiyEuQMtQ6aa72fgL5O6s";
String peopleId = "8734278942";
@override
void initState() {
super.initState();
requestPermissions();
}
void requestPermissions() async {
await [
Permission.camera,
].request();
}
void startFaceAuthenticator() async {
String result = "";
String description = "";
FaceAuthenticator faceAuthenticator =
new FaceAuthenticator(mobileToken: mobileToken, personId: peopleId);
// Put the others parameters here
try {
FaceAuthenticatorResult faceAuthenticatorResult =
await faceAuthenticator.start();
if (faceAuthenticatorResult is FaceAuthenticatorSuccess) {
result = "Success!";
description += "isMatch: " + faceAuthenticatorResult.isAlive.toString();
} else if (faceAuthenticatorResult is FaceAuthenticatorFailure) {
result = "Falha!";
description = "Error Message: " + faceAuthenticatorResult.errorMessage!;
} else {
result = "Closed!";
}
} on PlatformException catch (err) {
result = "Excpection!";
description = err.message!;
}
if (!mounted) return;
setState(() {
_result = result;
_description = description;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('FaceAuthenticator plugin example'),
),
body: Container(
margin: const EdgeInsets.all(20.0),
child: Column(
children: [
Row(
children: [
ElevatedButton(
child: Text('Start FaceAuthenticator'),
onPressed: () async {
startFaceAuthenticator();
},
)
],
),
Row(
children: [
Container(
margin: EdgeInsets.only(top: 10.0),
child: Text("Result: $_result"))
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text("Description:\n$_description",
overflow: TextOverflow.clip),
)
],
),
],
))));
}
}