actionHandler method
Future<CameraInternalMedia?>
actionHandler(
- CameraController cameraController,
- Completer<
CameraInternalMedia> completer, { - required Future<
ImageLocation> locationData(), - required DateTime dateTime,
- required DeviceOrientation orientation,
override
Implementation
@override
Future<CameraInternalMedia?> actionHandler(
CameraController cameraController,
Completer<CameraInternalMedia> completer, {
required final Future<ImageLocation> Function() locationData,
required DateTime dateTime,
required DeviceOrientation orientation,
}) async {
///Following default variable shouldDisplayPreview stops showing the preview if the timer has expired
Future<void> finishRecording({bool shouldDisplayPreview = true}) async {
if (!cameraController.value.isRecordingVideo) {
return;
}
timer?.cancel();
final video = await cameraController.stopVideoRecording();
if (shouldDisplayPreview) {
completer.complete(
CameraInternalVideo(
imageFile: video,
locationData: await locationData.call(),
dateTime: dateTime,
orientation: orientation,
),
);
await cameraController.pausePreview();
isCapturing.value = false;
cameraModuleCallbacks?.onCapture.call();
} else {
isCapturing.value = false;
bool? wasPreviewAccepted =
await cameraModuleCallbacks?.onTimerExpired?.call();
print("Was preview accepted $wasPreviewAccepted");
if (wasPreviewAccepted != null && wasPreviewAccepted) {
completer.complete(
CameraInternalVideo(
imageFile: video,
locationData: await locationData.call(),
dateTime: dateTime,
orientation: orientation,
),
);
}
}
}
if (!cameraController.value.isInitialized) {
if (kDebugMode) {
print('Error: select a camera first.');
}
throw Exception('Camera controller not init.');
}
if (cameraController.value.isRecordingVideo) {
try {
// await controller.setFlashMode(FlashMode.off);
await finishRecording();
} catch (e, s) {
log('Capture error', stackTrace: s, error: e);
rethrow;
}
} else {
isCapturing.value = true;
cameraController.startVideoRecording();
timer = Timer(maxLength, () async {
// if (timer!.isActive) {
await finishRecording(shouldDisplayPreview: false);
// }
});
}
return completer.future;
}