actionHandler method

  1. @override
Future<CameraInternalMedia?> actionHandler(
  1. CameraController cameraController,
  2. Completer<CameraInternalMedia> completer, {
  3. required Future<ImageLocation> locationData(),
  4. required DateTime dateTime,
  5. 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 {
  isCapturing.value = true;
  if (!cameraController.value.isInitialized) {
    if (kDebugMode) {
      print('Error: select a camera first.');
    }
    throw Exception('Camera controller not init.');
  }

  if (cameraController.value.isRecordingVideo) {
    if (kDebugMode) {
      print('A recording is already started, do nothing.');
    }
    throw Exception('Video Recording Under Process.');
  }

  try {
    // await controller.setFlashMode(FlashMode.off);
    final image = await cameraController.takePicture();
    completer.complete(
      CameraInternalImage(
        imageFile: image,
        locationData: await locationData.call(),
        dateTime: dateTime,
        orientation: orientation,
      ),
    );
    cameraModuleCallbacks?.onCapture.call();
    await cameraController.pausePreview();

    return completer.future;
  } catch (e, s) {
    log('Capture error', stackTrace: s, error: e);
    rethrow;
  } finally {
    isCapturing.value = false;
  }
}