getRootFolderPath method

Future<String?>? getRootFolderPath()

This tell user about where root directory located in flutter ****************

Implementation

Future<String?>? getRootFolderPath() async {
  Directory? directory;

  try {
    if (Platform.isAndroid) {
      if (await requestPermission(Permission.storage)) {
        directory = (await pp.getExternalStorageDirectory())!;
        String newPath = "";
        print(directory);
        List<String> paths = directory.path.split("/");
        for (int x = 1; x < paths.length; x++) {
          String folder = paths[x];
          if (folder != "Android") {
            newPath += "/" + folder;
          } else {
            break;
          }
        }
        directory = Directory(newPath);
      } else {
        return "";
      }
    } else {
      if (await requestPermission(Permission.photos)) {
        directory = await pp.getApplicationDocumentsDirectory();
      } else {
        return "";
      }
    }

    /*    if (!await directory.exists()) {
      await directory.create(recursive: true);
    }
    if (await directory.exists()) {
      return directory.path;
    }*/
  } catch (e) {
    print(e);
  }
  if (directory == null) return null;

  return directory.path;
}