getFileHandle method

Future<FileSystemFileHandle> getFileHandle(
  1. String name, {
  2. bool create = false,
})

Returns a Future fulfilled with a FileSystemFileHandle for a file with the specified name, within this directory.

name: a string representing the FileSystemHandle.name of the file you wish to retrieve.

create: when set to true if the file is not found, one with the specified name will be created and returned. Default false.

Throws a NotAllowedError if the state for the handle is not PermissionState.granted. Throws a MalformedNameError if the name specified is not a valid string or contains characters not allowed on the file system. Throws a TypeMismatchError if the named entry is a directory and not a file. Throws a NotFoundError if file doesn't exist and the create option is set to false or this requested directory could not be found at the time operation was processed.

Implementation

Future<FileSystemFileHandle> getFileHandle(String name, {bool create = false}) async {
  try {
    final options = [name, FileSystemGetFileOptions(create: create)];
    dynamic handle = await promiseToFuture(callMethod(this, "getFileHandle", options));

    return handle as FileSystemFileHandle;
  } catch (error) {
    if (jsIsNativeError(error, "NotAllowedError")) {
      throw NotAllowedError();
    } else if (jsIsNativeError(error, "TypeError")) {
      throw MalformedNameError();
    } else if (jsIsNativeError(error, "TypeMismatchError")) {
      throw TypeMismatchError();
    } else if (jsIsNativeError(error, "NotFoundError")) {
      throw NotFoundError();
    } else {
      rethrow;
    }
  }
}