openDocumentTree function
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.
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));
}