capturePhoto method
Implementation
Future<void> capturePhoto(BuildContext context) async {
if (state.isProcessing) {
return;
}
final controller = _ref.read(cameraControllerProvider);
if (controller == null || !controller.value.isInitialized) {
return;
}
// Extract context-dependent values before async operations
final cameraStrings = CameraStrings(context);
final setupFailedError = cameraStrings.setupFailed;
final imageDataTooLargeError = cameraStrings.imageDataTooLarge;
final serverCouldNotProcessImageError = cameraStrings.serverCouldNotProcessImage;
final mediaFormatNotSupportedError = cameraStrings.mediaFormatNotSupported;
_safeSetState(state.copyWith(isProcessing: true));
try {
final xFile = await controller.takePicture();
final imageFile = File(xFile.path);
_safeSetState(state.copyWith(capturedImage: imageFile));
await processImage(setupFailedError, imageDataTooLargeError, serverCouldNotProcessImageError, mediaFormatNotSupportedError);
} catch (e) {
_safeSetState(state.copyWith(isProcessing: false));
if (!_isDisposed) {
try {
_ref.read(verificationStateProvider.notifier).reportError(e.toString());
} catch (ex) {
// Handle error silently
}
}
}
}