startVideoRecording method Null safety

Future<void> startVideoRecording()

Start a video recording.

The video is returned as a XFile after calling stopVideoRecording. Throws a CameraException if the capture fails.

Implementation

Future<void> startVideoRecording() async {
  _throwIfNotInitialized('startVideoRecording');
  if (value.isRecordingVideo) {
    throw CameraException(
      'A video recording is already started.',
      'startVideoRecording was called when a recording is already started.',
    );
  }
  if (value.isStreamingImages) {
    throw CameraException(
      'A camera has started streaming images.',
      'startVideoRecording was called while a camera was streaming images.',
    );
  }

  try {
    await CameraPlatform.instance.startVideoRecording(_cameraId);
    value = value.copyWith(
        isRecordingVideo: true,
        isRecordingPaused: false,
        recordingOrientation: Optional<DeviceOrientation>.of(
            value.lockedCaptureOrientation ?? value.deviceOrientation));
  } on PlatformException catch (e) {
    throw CameraException(e.code, e.message);
  }
}