takePicture method Null safety

Future<XFile> takePicture()

Captures an image and returns the file where it was saved.

Throws a CameraException if the capture fails.


Future<XFile> takePicture() async {
  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);
    final XFile file = await CameraPlatform.instance.takePicture(_cameraId);
    value = value.copyWith(isTakingPicture: false);
    return file;
  } on PlatformException catch (e) {
    value = value.copyWith(isTakingPicture: false);
    throw CameraException(e.code, e.message);