getDownloadFolderPath method

  1. @override
Future<String?> getDownloadFolderPath()
override

Implementation

@override
Future<String?> getDownloadFolderPath() async {
  String? downloadPath = '';
  try {
    if (Platform.isAndroid) {
      // Get the external storage downloads directory path on Android using the platform-specific channel.
      downloadPath = await methodChannel.invokeMethod<String?>(
        'getExternalStoragePublicDirectory',
        {'type': _androidDownloadsFolderType},
      );
    } else if (Platform.isIOS) {
      // Get the ApplicationDocumentsDirectory path for iOS.
      downloadPath = (await path.getApplicationDocumentsDirectory()).path;
    } else if (Platform.isMacOS) {
      // Get the Downloads directory path for MacOS.
      downloadPath = (await path.getDownloadsDirectory())?.path;
    } else if (Platform.isWindows) {
      // Get the Downloads directory path for Windows using the Windows-specific path provider.
      downloadPath =
          await pathwindows.PathProviderWindows().getDownloadsPath();
    }
  } on Exception catch (_) {
    // Rethrow any exception that occurs during the path retrieval process.
    rethrow;
  }
  return downloadPath;
}