Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[path_provider] now supports getDownloadsDirectory() on macOS. #2436

Merged
merged 11 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/path_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 20 additions & 0 deletions packages/path_provider/lib/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,23 @@ Future<List<Directory>> 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<Directory> 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<String>('getDownloadsDirectory');
if (path == null) {
return null;
}
return Directory(path);
}
4 changes: 4 additions & 0 deletions packages/path_provider/path_provider_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.3

* Added support for user's downloads directory.

## 0.0.2+1

* Update README.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/path_provider/path_provider_macos/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/path_provider/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions packages/path_provider/test/path_provider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}