stopImageStream method

Future<void> stopImageStream()

Stop streaming images from platform camera.

Throws a CameraException if image streaming was not started or video recording was started.

Implementation

Future<void> stopImageStream() async {
  if (!value.isInitialized || _isDisposed) {
    throw CameraException(
      'Uninitialized CameraController',
      'stopImageStream was called on uninitialized CameraController.',
    );
  }
  if (value.isRecordingVideo) {
    throw CameraException(
      'A video recording is already started.',
      'stopImageStream was called while a video is being recorded.',
    );
  }
  if (!value.isStreamingImages) {
    throw CameraException(
      'No camera is streaming images',
      'stopImageStream was called when no camera is streaming images.',
    );
  }

  try {
    value = value.copyWith(isStreamingImages: false);
    await _channel.invokeMethod<void>('stopImageStream');
  } on PlatformException catch (e) {
    throw CameraException(e.code, e.message!);
  }

  await _imageStreamSubscription!.cancel();
  _imageStreamSubscription = null;
}