getStorageList static method

Future<List<Directory>> getStorageList()

Get list of available storage in the device returns an empty list if there is no storage

Implementation

static Future<List<Directory>> getStorageList() async {
  if (Platform.isAndroid) {
    List<Directory> storages = (await getExternalStorageDirectories())!;
    storages = storages.map((Directory e) {
      final List<String> splitedPath = e.path.split("/");
      return Directory(splitedPath
          .sublist(
              0, splitedPath.indexWhere((element) => element == "Android"))
          .join("/"));
    }).toList();
    return storages;
  } else if (Platform.isLinux) {
    final Directory dir = await getApplicationDocumentsDirectory();

    // Gives the home directory.
    final Directory home = dir.parent;

    // you may provide root directory.
    // final Directory root = dir.parent.parent.parent;
    return [home];
  }
  return [];
}