pickFileAndDirectoryPaths method

  1. @override
Future<List<String>?> pickFileAndDirectoryPaths({
  1. String? initialDirectory,
  2. FileType type = FileType.any,
  3. List<String>? allowedExtensions,
})
override

Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths.

Platform Support: As of right now, this functionality is only supported on macOS.

initialDirectory can be optionally set to an absolute path to specify where the dialog should open. On macOS the home directory shortcut (~/) is not necessary and passing it will be ignored. On macOS if the initialDirectory is invalid the user directory or previously valid directory will be used.

The file type filter type defaults to FileType.any. Optionally, allowedExtensions might be provided (e.g. ["pdf", "svg", "jpg"]).

Returns a Future<List<String>?> that resolves to a list of absolute paths for the selected files and directories. If the user cancels the dialog or if the paths cannot be resolved, the method returns null.

Implementation

@override
Future<List<String>?> pickFileAndDirectoryPaths({
  String? initialDirectory,
  FileType type = FileType.any,
  List<String>? allowedExtensions,
}) async {
  final fileFilter = fileTypeToFileFilter(
    type,
    allowedExtensions,
  );

  final filePaths = await methodChannel.invokeListMethod<String>(
    'pickFileAndDirectoryPaths',
    <String, dynamic>{
      'allowedExtensions': fileFilter,
      'initialDirectory': escapeInitialDirectory(initialDirectory),
    },
  );

  return filePaths;
}