diff --git a/packages/path_provider/CHANGELOG.md b/packages/path_provider/CHANGELOG.md index ee7163f1cf56..ad26ead1ca3b 100644 --- a/packages/path_provider/CHANGELOG.md +++ b/packages/path_provider/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.6.0 + +* Support for retrieving the downloads directory was added. + The call for this is `getDownloadsDirectory`. + ## 1.5.1 * Remove the deprecated `author:` field from pubspec.yaml diff --git a/packages/path_provider/lib/path_provider.dart b/packages/path_provider/lib/path_provider.dart index 52aceb786477..b27cc4bc3fcb 100644 --- a/packages/path_provider/lib/path_provider.dart +++ b/packages/path_provider/lib/path_provider.dart @@ -216,3 +216,23 @@ Future> getExternalStorageDirectories({ return paths.map((String path) => Directory(path)).toList(); } + +/// Path to the directory where downloaded files can be stored. +/// This is typically only relevant on desktop operating systems. +/// +/// On Android and on iOS, this function throws an [UnsupportedError] as no equivalent +/// path exists. +Future getDownloadsDirectory() async { + if (_platform.isAndroid) { + throw UnsupportedError('Functionality not available on Android'); + } + if (_platform.isIOS) { + throw UnsupportedError('Functionality not available on iOS'); + } + final String path = + await _channel.invokeMethod('getDownloadsDirectory'); + if (path == null) { + return null; + } + return Directory(path); +} diff --git a/packages/path_provider/path_provider_macos/CHANGELOG.md b/packages/path_provider/path_provider_macos/CHANGELOG.md index 3e3607e44a33..ae674a2113a5 100644 --- a/packages/path_provider/path_provider_macos/CHANGELOG.md +++ b/packages/path_provider/path_provider_macos/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.3 + +* Added support for user's downloads directory. + ## 0.0.2+1 * Update README. diff --git a/packages/path_provider/path_provider_macos/macos/Classes/PathProviderPlugin.swift b/packages/path_provider/path_provider_macos/macos/Classes/PathProviderPlugin.swift index 4ceb00634097..cb56fc49769c 100644 --- a/packages/path_provider/path_provider_macos/macos/Classes/PathProviderPlugin.swift +++ b/packages/path_provider/path_provider_macos/macos/Classes/PathProviderPlugin.swift @@ -49,6 +49,8 @@ public class PathProviderPlugin: NSObject, FlutterPlugin { result(path) case "getLibraryDirectory": result(getDirectory(ofType: FileManager.SearchPathDirectory.libraryDirectory)) + case "getDownloadsDirectory": + result(getDirectory(ofType: FileManager.SearchPathDirectory.downloadsDirectory)) default: result(FlutterMethodNotImplemented) } diff --git a/packages/path_provider/path_provider_macos/pubspec.yaml b/packages/path_provider/path_provider_macos/pubspec.yaml index 82acee955a0a..ca04d59a7fd8 100644 --- a/packages/path_provider/path_provider_macos/pubspec.yaml +++ b/packages/path_provider/path_provider_macos/pubspec.yaml @@ -1,6 +1,6 @@ name: path_provider_macos description: macOS implementation of the path_provider plugin -version: 0.0.2+1 +version: 0.0.3 homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_macos flutter: diff --git a/packages/path_provider/pubspec.yaml b/packages/path_provider/pubspec.yaml index 730e7a5b5c1e..e884c0f4aecd 100644 --- a/packages/path_provider/pubspec.yaml +++ b/packages/path_provider/pubspec.yaml @@ -2,7 +2,7 @@ name: path_provider description: Flutter plugin for getting commonly used locations on the Android & iOS file systems, such as the temp and app data directories. homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider -version: 1.5.1 +version: 1.6.0 flutter: plugin: diff --git a/packages/path_provider/test/path_provider_test.dart b/packages/path_provider/test/path_provider_test.dart index 7af37888492f..5b875e3bc51e 100644 --- a/packages/path_provider/test/path_provider_test.dart +++ b/packages/path_provider/test/path_provider_test.dart @@ -226,4 +226,12 @@ void main() { ); expect(directories.map((Directory d) => d.path).toList(), equals(paths)); }); + + test('DownloadsDirectory path macos test', () async { + setMockPathProviderPlatform(FakePlatform(operatingSystem: 'macos')); + final String fakePath = "/foo/bar/baz"; + response = fakePath; + final Directory directory = await getDownloadsDirectory(); + expect(directory.path, equals(fakePath)); + }); }