captureCurrentStep method
Called automatically after the hold duration, or manually if FaceCaptureConfig.autoCapture is false and your UI wires up a button.
Implementation
Future<void> captureCurrentStep() async {
final camController = _cameraController;
if (camController == null || _isCapturing) return;
_isCapturing = true;
try {
await _stopImageStream(camController);
if (_disposed) return;
final xfile = await camController.takePicture();
if (_disposed) return;
final updatedCaptured = [
..._state.captured,
CapturedFaceImage(pose: currentStep.pose, file: File(xfile.path)),
];
final nextIndex = _state.currentStepIndex + 1;
final isDone = nextIndex >= _steps.length;
_update(
_state.copyWith(
captured: updatedCaptured,
currentStepIndex: isDone ? _state.currentStepIndex : nextIndex,
phase: isDone ? FaceCapturePhase.allCaptured : FaceCapturePhase.ready,
faceDetected: false,
),
);
if (!isDone && !_disposed && !camController.value.isStreamingImages) {
_streamFramesSkipped = 0;
await camController.startImageStream(_onCameraFrame);
}
} catch (e) {
_update(
_state.copyWith(
phase: FaceCapturePhase.cameraError,
errorMessage: e.toString(),
),
);
} finally {
_isCapturing = false;
}
}