takePhoto method
Future<CaptureRequest>
takePhoto({
- OnPhotoCallback? onPhoto,
- OnPhotoFailedCallback? onPhotoFailed,
Photos taken are in JPEG format. filePath
must end with .jpg
You can listen to cameraSetup.mediaCaptureStream
to get updates
of the photo capture (capturing, success/failure)
Implementation
Future<CaptureRequest> takePhoto({
OnPhotoCallback? onPhoto,
OnPhotoFailedCallback? onPhotoFailed,
}) async {
CaptureRequest captureRequest =
await filePathBuilder(sensorConfig.sensors.whereNotNull().toList());
final mediaCapture = MediaCapture.capturing(captureRequest: captureRequest);
if (!mediaCapture.isPicture) {
throw ("CaptureRequest must be a picture. ${captureRequest.when(
single: (single) => single.file!.path,
multiple: (multiple) => multiple.fileBySensor.values.first!.path,
)}");
}
_mediaCapture = mediaCapture;
try {
final succeeded = await CamerawesomePlugin.takePhoto(captureRequest);
if (succeeded) {
await FilterHandler().apply(
captureRequest: captureRequest,
filter: filter,
);
_mediaCapture = MediaCapture.success(captureRequest: captureRequest);
onPhoto?.call(captureRequest);
} else {
_mediaCapture = MediaCapture.failure(captureRequest: captureRequest);
onPhotoFailed?.call(Exception("Failed to take photo"));
}
} on Exception catch (e) {
_mediaCapture = MediaCapture.failure(
captureRequest: captureRequest,
exception: e,
);
}
return captureRequest;
}