openDocumentTree function

Future<Uri?> openDocumentTree({
  1. bool grantWritePermission = true,
  2. bool persistablePermission = true,
  3. Uri? initialUri,
})

Start Activity Action: Allow the user to pick a directory subtree.

When invoked, the system will display the various DocumentsProvider instances installed on the device, letting the user navigate through them. Apps can fully manage documents within the returned directory.

Refer to details.

support the initial directory of the directory picker.

Implementation

Future<Uri?> openDocumentTree({
  bool grantWritePermission = true,
  bool persistablePermission = true,
  Uri? initialUri,
}) async {
  const kOpenDocumentTree = 'openDocumentTree';

  final args = <String, dynamic>{
    'grantWritePermission': grantWritePermission,
    'persistablePermission': persistablePermission,
    if (initialUri != null) 'initialUri': '$initialUri',
  };

  final selectedDirectoryUri =
      await kDocumentFileChannel.invokeMethod<String?>(kOpenDocumentTree, args);

  return selectedDirectoryUri?.apply((e) => Uri.parse(e));
}