capturedFile method

Future<File?> capturedFile({
  1. bool? allowRecord,
})

Opens the camera screen and returns the captured file path.

Navigates to the CameraScreen and waits for a file to be captured. Returns the file path if successful, otherwise returns null.

Implementation

Future<File?> capturedFile({bool? allowRecord}) async {
  File? capturedPath;
  if (kIsWeb) {
    throw "Camera is not supported for web";
  }
  await Navigator.push(
    context,
    MaterialPageRoute(
        builder: (context) => CameraScreen(
              allowRecord: allowRecord ?? false,
            )),
  ).then((path) async {
    if (path != null) {
      capturedPath = path;
    }
  }).catchError((e) {
    capturedPath = null;
  });

  return capturedPath;
}