takePicture method

Future<File?> takePicture()

Implementation

Future<File?> takePicture() async {
  final CameraController? cameraController =
      widget._controller.cameraController;

  if (cameraController!.value.isTakingPicture) {
    // A capture is already pending, do nothing.
    return null;
  }

  try {
    XFile file = await cameraController.takePicture();
    final bytes = kIsWeb ? await file.readAsBytes() : null;
    final fileSize = await file.length();

    return File(
        file.name, file.path.split('.').last, fileSize, file.path, bytes);
  } on CameraException catch (_) {
    return null;
  }
}