captureFace method

Future<({XFile imageFile, Uint8List uint8list})?> captureFace()

Implementation

Future<({XFile imageFile, Uint8List uint8list})?> captureFace() async {
  try {
    Utills.printLogs("FaceErrorStatus 3 capture $hasCapturedImage");
    hasCapturedImage = true;

    final XFile? file = await cameraController?.takePicture();
    if (file == null) return null;

    final bytes = await file.readAsBytes();
    final isFrontCamera = cameraController?.description.lensDirection ==
        CameraLensDirection.front;

    Uint8List finalBytes = bytes;
    // Notify captured image
    capturedImageNotifier.value =
        CapturedImageData(image: file, uint8list: finalBytes);

    if (isFrontCamera) {
      final originalImage = img.decodeImage(bytes);
      if (originalImage != null) {
        final mirroredImage = img.flipHorizontal(originalImage);
        final cropped =
            Utills.cropImage(mirroredImage); // Crop after mirroring
        finalBytes = Uint8List.fromList(img.encodeJpg(cropped));
      }
    }

    return (imageFile: file, uint8list: finalBytes);
  } catch (e) {
    hasCapturedImage = false;
    if (kDebugMode) {
      Utills.printLogs("FaceErrorStatus: $e");
    }
    return null;
  }
}