downloadDirectory static method

Future<String?> downloadDirectory(
  1. String folderName
)

Implementation

static Future<String?> downloadDirectory(String folderName) async {
  String? path;

  try {
    const downloadPath = '/storage/emulated/0/Download';
    // Put file in global download folder, if for an unknown reason it didn't exist, we fallback
    path = '$downloadPath/$folderName';
    if (!await Directory(path).exists()) {
      await Directory(path).create(recursive: true);
    }
  } catch (error) {
    if (kDebugMode) {
      print(error);
    }
  }
  try {
    if (!await Directory(path ?? '').exists()) {
      final directory = await getExternalStorageDirectory();
      path = directory?.path;
    }
  } catch (error) {
    if (kDebugMode) {
      print(error);
    }
  }
  return path;
}