getDirectoryHandle method

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

Returns a Future fulfilled with a FileSystemDirectoryHandle for a subdirectory with the specified name, within this directory.

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

create: when set to true if the directory 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 TypeMismatchError if the returned entry is a file and not a directory. Throws a NotFoundError if directory 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<FileSystemDirectoryHandle> getDirectoryHandle(String name, {bool create = false}) async {
  try {
    final options = [name, FileSystemGetDirectoryOptions(create: create)];
    dynamic handle = await promiseToFuture(callMethod(this, "getDirectoryHandle", options));

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