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.

The stopImageStream method is only available on platforms that report support for image streaming via supportsImageStreaming.

Implementation

Future<void> stopImageStream() async {
  assert(supportsImageStreaming());
  _throwIfNotInitialized('stopImageStream');
  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 _imageStreamSubscription?.cancel();
    _imageStreamSubscription = null;
  } on PlatformException catch (e) {
    throw CameraException(e.code, e.message);
  }
}