getFilePickerDirectoriesForMediaType method

Future<List<Directory>> getFilePickerDirectoriesForMediaType(
  1. MediaType type
)

Returns valid file picker directories. If there is a last picked directory for a media type, this will be included as first on the list. Otherwise, external root directories will be included.

Implementation

Future<List<Directory>> getFilePickerDirectoriesForMediaType(
    MediaType type) async {
  List<Directory> directories = [];
  Directory? lastPickedDirectory = getLastPickedDirectory(type);
  if (lastPickedDirectory != null) {
    directories.add(lastPickedDirectory);
  }

  List<String> paths = await ExternalPath.getExternalStorageDirectories();
  for (String path in paths) {
    Directory directory = Directory(path);
    if (!directories.contains(directory)) {
      directories.add(directory);
    }
  }

  return directories;
}