Skip to content

Commit aa964a3

Browse files
[path_provider] Document null vs UnsupportedError return semantics (#11793)
Updates the dartdoc for `getDownloadsDirectory` in `path_provider` and the matching `getDownloadsPath` contract on `PathProviderPlatform` to explain both return-value cases: - `null` — the platform supports the concept of a downloads directory but no such directory is currently available (concrete example: Linux without `xdg-user-dir` installed, or where `xdg-user-dir` fails when called). - `UnsupportedError` — the current platform has no concept of a downloads directory at all. Previously the dartdoc only mentioned the `UnsupportedError` case, which left users unsure when they might see a `null` result. The wording matches the explanations already given by maintainers in the linked issue thread. Fixes flutter/flutter#143238 ## Pre-Review Checklist This is a documentation-only change to public dartdoc comments. No code behavior changes; no new tests are required per the auto-exempt rules for changes that only affect comments/documentation.
1 parent 7d0943b commit aa964a3

6 files changed

Lines changed: 23 additions & 6 deletions

File tree

packages/path_provider/path_provider/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
## NEXT
1+
## 2.1.6
22

33
* Updates minimum supported SDK version to Flutter 3.38/Dart 3.10.
44
* Updates README to reflect currently supported OS versions for the latest
55
versions of the endorsed platform implementations.
66
* Applications built with older versions of Flutter will continue to
77
use compatible versions of the platform implementations.
8+
* Documents the difference between a `null` return and an `UnsupportedError`
9+
from `getDownloadsDirectory`.
810

911
## 2.1.5
1012

packages/path_provider/path_provider/lib/path_provider.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,13 @@ Future<List<Directory>?> getExternalStorageDirectories({
207207
/// The returned directory is not guaranteed to exist, so clients should verify
208208
/// that it does before using it, and potentially create it if necessary.
209209
///
210-
/// Throws an [UnsupportedError] if this is not supported on the current
211-
/// platform.
210+
/// Returns `null` when the current platform supports the concept of a
211+
/// downloads directory but no such directory is currently available. For
212+
/// example, on Linux this can happen when `xdg-user-dir` is not installed
213+
/// or fails when called.
214+
///
215+
/// Throws an [UnsupportedError] when the current platform has no concept of
216+
/// a downloads directory at all.
212217
Future<Directory?> getDownloadsDirectory() async {
213218
final String? path = await _platform.getDownloadsPath();
214219
if (path == null) {

packages/path_provider/path_provider/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: path_provider
22
description: Flutter plugin for getting commonly used locations on host platform file systems, such as the temp and app data directories.
33
repository: https://github.com/flutter/packages/tree/main/packages/path_provider/path_provider
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+path_provider%22
5-
version: 2.1.5
5+
version: 2.1.6
66

77
environment:
88
sdk: ^3.10.0

packages/path_provider/path_provider_platform_interface/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
## NEXT
1+
## 2.1.3
22

33
* Updates minimum supported SDK version to Flutter 3.38/Dart 3.10.
4+
* Documents the implementation contract for `null` versus `UnsupportedError`
5+
return semantics on `getDownloadsPath`.
46

57
## 2.1.2
68

packages/path_provider/path_provider_platform_interface/lib/path_provider_platform_interface.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ abstract class PathProviderPlatform extends PlatformInterface {
9393

9494
/// Path to the directory where downloaded files can be stored.
9595
/// This is typically only relevant on desktop operating systems.
96+
///
97+
/// Implementations should return `null` when the platform supports the
98+
/// concept of a downloads directory but no such directory is currently
99+
/// available (for example, on Linux when `xdg-user-dir` is not installed
100+
/// or fails when called).
101+
///
102+
/// Implementations should throw an [UnsupportedError] when the platform
103+
/// has no concept of a downloads directory at all.
96104
Future<String?> getDownloadsPath() {
97105
throw UnimplementedError('getDownloadsPath() has not been implemented.');
98106
}

packages/path_provider/path_provider_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/path_provider
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+path_provider%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.1.2
7+
version: 2.1.3
88

99
environment:
1010
sdk: ^3.10.0

0 commit comments

Comments
 (0)