instance of the issue I received
code from the problematic program
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'bundle:flutter/cupertino.dart';
import 'bundle:flutter/materials.dart';
import 'bundle:flutter/providers.dart';
import 'bundle:picture/picture.dart' as imglib;
import 'bundle:shared_preferences/shared_preferences.dart';
import 'bundle:digicam/digicam.dart';
import 'bundle:google_mlkit_face_detection/google_mlkit_face_detection.dart';
import 'bundle:flutter_face_api/face_api.dart' as Regula;
import '../conn/getFoto.dart';
String nama = "-";
String pin = "-";
String instruk = "Scanning...";
String _similarity = "nil";
var takenPicture;
var takenPicturePath;
int camNum = 1;
double persenCocok = 0;
bool faceUp = false;
bool faceDown = false;
bool faceRight = false;
bool faceLeft = false;
bool faceCenter = false;
class AbsenFoto extends StatefulWidget {
const AbsenFoto({tremendous.key});
@override
State<AbsenFoto> createState() => _AbsenFotoState();
}
class _AbsenFotoState extends State<AbsenFoto> {
Record<CameraDescription>? cameras;
CameraController? controller;
var faceDetector;
late Record<Face> _faces;
Colour topBar = Colour.fromRGBO(22, 149, 0, 1.0);
Colour dataBackgroundColor = Colour.fromRGBO(152, 136, 136, 1.0);
Colour switchCameraButtonColor = Colour.fromRGBO(3, 217, 254, 1.0);
Colour batalButton = Colour.fromRGBO(234, 0, 1, 1.0);
@override
void initState() {
camInit();
_facesInit();
getFoto().gettingFoto();
tremendous.initState();
}
@override
void dispose() {
faceDetector.shut();
controller?.dispose();
faceUp = false;
faceDown = false;
faceRight = false;
faceLeft = false;
faceCenter = false;
instruk = "Scanning...";
tremendous.dispose();
}
@override
Widget construct(BuildContext context) {
setState(() {
getNama();
});
return Scaffold(
appBar: AppBar(
title: Textual content(
"Absensi Mangusada",
),
backgroundColor: topBar,
foregroundColor: CupertinoColors.white,
),
physique: Padding(
padding: EdgeInsets.solely(prime: 20),
baby: SingleChildScrollView(
baby: Middle(
baby: Column(
kids: [
Container(
height: 380,
width: 240,
child: showCam(),
),
SizedBox(
height: 50,
),
Text(
instruk,
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
SizedBox(
height: 16,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: dataBackgroundColor,
),
height: 100,
width: 310,
padding: EdgeInsets.only(top: 30, left: 16),
child: Align(
alignment: Alignment.centerLeft,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 8,
),
Text(
nama,
style: TextStyle(color: CupertinoColors.white),
),
Text(
pin,
style: TextStyle(color: CupertinoColors.white),
),
],
),
),
),
SizedBox(
peak: 16,
),
ElevatedButton(
onPressed: () async {
if (camNum == 0) {
camNum = 1;
await updateController(cameras![camNum]);
} else if (camNum == 1) {
camNum = 0;
await updateController(cameras![camNum]);
}
},
baby: Textual content("SWITCH CAMERA"),
model: ButtonStyle(
backgroundColor:
MaterialStatePropertyAll(switchCameraButtonColor),
foregroundColor:
MaterialStatePropertyAll(CupertinoColors.white),
minimumSize: MaterialStateProperty.all(
Measurement(310, 60),
),
form: MaterialStatePropertyAll(
RoundedRectangleBorder(
borderRadius: BorderRadius.round(10),
),
),
),
),
SizedBox(
peak: 16,
),
ElevatedButton(
onPressed: () {
if (mounted) {
controller!.dispose();
faceUp = false;
faceDown = false;
faceRight = false;
faceLeft = false;
faceCenter = false;
}
Navigator.pushReplacementNamed(context, '/absen');
},
baby: Textual content("BATAL"),
model: ButtonStyle(
backgroundColor: MaterialStatePropertyAll(batalButton),
foregroundColor:
MaterialStatePropertyAll(CupertinoColors.white),
minimumSize: MaterialStateProperty.all(
Measurement(310, 60),
),
form: MaterialStatePropertyAll(
RoundedRectangleBorder(
borderRadius: BorderRadius.round(10),
),
),
),
),
],
),
),
),
),
);
}
camInit() async {
cameras = await availableCameras();
if (cameras != null) {
controller = CameraController(cameras![1], ResolutionPreset.excessive, imageFormatGroup: Platform.isAndroid ? ImageFormatGroup.nv21 : ImageFormatGroup.bgra8888, enableAudio: false);
await controller!.initialize().then((_) {
if (!mounted) {
return;
}
setState(() {});
});
} else {
print("NO any digicam discovered");
}
}
showCam() {
if (controller == null) {
return Middle(baby: Textual content("Loading Digicam..."),);
} else if (!controller!.worth.isInitialized) {
return Middle(baby: CircularProgressIndicator(),);
} else {
return Stack(
kids: [
CameraPreview(controller!),
FutureBuilder<List<Face>>(
future: _detectFaces(),
builder: (context, snapshot) {
return Container();
}
),
],
);
}
}
_facesInit() {
remaining FaceDetectorOptions choices = FaceDetectorOptions(
enableClassification: true,
enableTracking: true,
enableLandmarks: true,
enableContours: true,
performanceMode: FaceDetectorMode.correct
);
faceDetector = FaceDetector(choices: choices);
}
updateController(CameraDescription description) {
controller?.dispose().then((worth) async {
setState(() {});
controller = CameraController(description, ResolutionPreset.excessive, imageFormatGroup: Platform.isAndroid ? ImageFormatGroup.nv21 : ImageFormatGroup.bgra8888, enableAudio: false);
controller?.initialize().then((_) {
setState(() {});
});
});
}
Future<Record<Face>> _detectFaces() async {
takenPicture = await controller?.takePicture();
takenPicturePath = takenPicture.path;
remaining inputImage = InputImage.fromFilePath(takenPicture!.path);
_faces = await faceDetector.processImage(inputImage);
setState(() {
if (_faces.isEmpty) {
instruk = "Wajah tidak terdeteksi";
} else {
instruk = "Scanning...";
if (faceUp == false) {
instruk = "Hadap ke atas";
_faces.single.headEulerAngleX! >= 20 ? faceUp = true : faceUp = false ;
} else if (faceDown == false) {
instruk = "Hadap ke bawah";
_faces.single.headEulerAngleX! <= -20 ? faceDown = true : faceDown = false ;
} else if (faceRight == false) {
instruk = "Toleh ke kanan";
_faces.single.headEulerAngleY! <= -20 ? faceRight = true : faceRight = false ;
} else if (faceLeft == false) {
instruk = "Toleh ke kiri";
_faces.single.headEulerAngleY! >= 20 ? faceLeft = true : faceLeft = false ;
} else if (faceCenter == false) {
instruk = "Lihat ke depan";
(_faces.single.headEulerAngleY! >= -5 && _faces.single.headEulerAngleY! <= 5) && (_faces.single.headEulerAngleX! >= -5 && _faces.single.headEulerAngleX! <= 5)
? faceCenter = true : faceCenter = false ;
} else {
instruk = "Harap tunggu...nTahan Posisi Anda";
}
}
});
if (faceUp == true && faceDown == true && faceRight == true && faceLeft == true && faceCenter == true) {
instruk = "Harap tunggu...nTahan Posisi Anda";
compareFace();
if (persenCocok >= 95) {
await controller?.pausePreview();
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Textual content("Verifikasi Liveness Berhasil!"),
content material: Textual content('Anda asli!nWajah anda $_similarity sama dengan yang ada di server'),
actions: [
TextButton(
onPressed: () {
setState(() {
faceUp = false;
faceDown = false;
faceRight = false;
faceLeft = false;
faceCenter = false;
});
Navigator.pushNamedAndRemoveUntil(context, "/home", (route) => false);
},
child: Text("OK"),
)
],
);
}
);
} else if (_similarity == "error") {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Textual content("Verifikasi Liveness Berhasil!"),
content material: Textual content('Anda asli!nTetapi wajah anda tidak sama dengan gambar yang ada di server'),
actions: [
TextButton(
onPressed: () {
setState(() {
faceUp = false;
faceDown = false;
faceRight = false;
faceLeft = false;
faceCenter = false;
});
Navigator.pushNamedAndRemoveUntil(context, "/home", (route) => false);
},
child: Text("OK"),
)
],
);
}
);
} else {
instruk = "Harap tunggu...nTahan Posisi Anda";
}
}
return _faces;
}
compareFace() async {
var image1 = Regula.MatchFacesImage();
var image2 = Regula.MatchFacesImage();
imglib.Picture? FileImage1 = imglib.decodeImage(File(takenPicturePath).readAsBytesSync());
imglib.Picture? FileImage2 = imglib.decodeImage(File(getFoto().getPathPhoto()).readAsBytesSync());
Record<int> image1Bytes = imglib.encodePng(FileImage1!);
Record<int> image2Bytes = imglib.encodePng(FileImage2!);
image1.bitmap = base64Encode(image1Bytes);
image1.imageType = Regula.ImageType.PRINTED;
image2.bitmap = base64Encode(image2Bytes);
image2.imageType = Regula.ImageType.PRINTED;
if (image1.bitmap == null ||
image1.bitmap == "" ||
image2.bitmap == null ||
image2.bitmap == "") return 0;
var request = await Regula.MatchFacesRequest();
request.photographs = [image1, image2];
Regula.FaceSDK.matchFaces(jsonEncode(request)).then((worth) {
var response = Regula.MatchFacesResponse.fromJson(json.decode(worth));
Regula.FaceSDK.matchFacesSimilarityThresholdSplit(
jsonEncode(response!.outcomes), 0.75)
.then((str) {
var cut up = Regula.MatchFacesSimilarityThresholdSplit.fromJson(
json.decode(str));
setState(() {
_similarity = cut up!.matchedFaces.isNotEmpty
? ("${(cut up.matchedFaces[0]!.similarity! * 100).toStringAsFixed(2)}%")
: "error";
persenCocok = cut up.matchedFaces.isNotEmpty
? (cut up.matchedFaces[0]!.similarity! * 100)
: 0;
});
});
});
return _similarity;
}
getNama() async {
remaining prefs = await SharedPreferences.getInstance();
nama = prefs.get("consumer").toString();
pin = prefs.get("pin").toString();
}
}
I attempted operating the code on Android and it efficiently displayed the digicam and face scanning.
and once I kind the code on the iOS gadget the digicam is spamming taking pictures and flashing on the iPhone display screen
I hope every part can run easily like on Android