takePhoto method
Captures a still, or starts/stops recording in video mode.
Implementation
Future<void> takePhoto() async {
if (_closed || _capturing) return;
if (!photo) {
await endVideo();
return;
}
if (recording) return;
_capturing = true;
_safeNotify();
try {
final capture = await session.useController((controller) async {
final physical = XSensor.orientation;
final sensor = controller.description.sensorOrientation;
final isFront = controller.description.lens == XCameraLens.front;
await controller.setFlashMode(
flashOn && !isFront ? XFlashMode.always : XFlashMode.off,
);
final file = await controller.takePicture();
return (
file: file,
physical: physical,
sensorOrientation: sensor,
isFrontCamera: isFront,
);
});
if (capture == null) return;
final normalized = await normalizeCameraCapture(
io.File(capture.file.path),
physical: capture.physical,
sensorOrientation: capture.sensorOrientation,
isFrontCamera: capture.isFrontCamera,
);
if (!_closed) pop(ImageMedia(file: normalized));
} catch (error, stack) {
_captureError(error, stack);
} finally {
_capturing = false;
_safeNotify();
}
}