takePicture method

Future<void> takePicture(
  1. String path
)

Captures an image and saves it to path.

A path can for example be obtained using path_provider.

If a file already exists at the provided path an error will be thrown. The file can be read as this function returns.

Throws a CameraException if the capture fails.

Implementation

Future<void> takePicture(String path) async {
  if (!value.isInitialized! || _isDisposed) {
    throw CameraException(
      'Uninitialized CameraController.',
      'takePicture was called on uninitialized CameraController',
    );
  }
  if (value.isTakingPicture!) {
    throw CameraException(
      'Previous capture has not returned yet.',
      'takePicture was called before the previous capture returned.',
    );
  }
  try {
    value = value.copyWith(isTakingPicture: true);
    await _channel.invokeMethod<void>(
      'takePicture',
      <String, dynamic>{'textureId': _textureId, 'path': path},
    );
    value = value.copyWith(isTakingPicture: false);
  } on PlatformException catch (e) {
    value = value.copyWith(isTakingPicture: false);
    throw CameraException(e.code, e.message);
  }
}