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

Commit abeb29f

Browse files
authored
[path_provider] Fixed support for querying the root external storage directory (#6036)
1 parent 5d72e9a commit abeb29f

File tree

9 files changed

+29
-24
lines changed

9 files changed

+29
-24
lines changed

packages/path_provider/path_provider_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.16
2+
3+
* Fixes bug with `getExternalStoragePaths(null)`.
4+
15
## 2.0.15
26

37
* Switches the medium from MethodChannels to Pigeon.

packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/Messages.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
4+
// Autogenerated from Pigeon (v3.2.0), do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66

77
package io.flutter.plugins.pathprovider;
@@ -23,16 +23,17 @@
2323
public class Messages {
2424

2525
public enum StorageDirectory {
26-
music(0),
27-
podcasts(1),
28-
ringtones(2),
29-
alarms(3),
30-
notifications(4),
31-
pictures(5),
32-
movies(6),
33-
downloads(7),
34-
dcim(8),
35-
documents(9);
26+
root(0),
27+
music(1),
28+
podcasts(2),
29+
ringtones(3),
30+
alarms(4),
31+
notifications(5),
32+
pictures(6),
33+
movies(7),
34+
downloads(8),
35+
dcim(9),
36+
documents(10);
3637

3738
private int index;
3839

packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ private List<String> getPathProviderExternalCacheDirectories() {
125125

126126
private String getStorageDirectoryString(@NonNull Messages.StorageDirectory directory) {
127127
switch (directory) {
128+
case root:
129+
return null;
128130
case music:
129131
return "music";
130132
case podcasts:

packages/path_provider/path_provider_android/example/integration_test/path_provider_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void main() {
6868
final List<String>? directories =
6969
await provider.getExternalStoragePaths(type: type);
7070
expect(directories, isNotNull);
71+
expect(directories, isNotEmpty);
7172
for (final String result in directories!) {
7273
_verifySampleFile(result, '$type');
7374
}

packages/path_provider/path_provider_android/lib/messages.g.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
4+
// Autogenerated from Pigeon (v3.2.0), do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name
77
// @dart = 2.12
@@ -12,6 +12,7 @@ import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer;
1212
import 'package:flutter/services.dart';
1313

1414
enum StorageDirectory {
15+
root,
1516
music,
1617
podcasts,
1718
ringtones,

packages/path_provider/path_provider_android/lib/path_provider_android.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
66
import 'messages.g.dart' as messages;
77

8-
messages.StorageDirectory _convertStorageDirectory(StorageDirectory directory) {
8+
messages.StorageDirectory _convertStorageDirectory(
9+
StorageDirectory? directory) {
910
switch (directory) {
11+
case null:
12+
return messages.StorageDirectory.root;
1013
case StorageDirectory.music:
1114
return messages.StorageDirectory.music;
1215
case StorageDirectory.podcasts:
@@ -73,10 +76,8 @@ class PathProviderAndroid extends PathProviderPlatform {
7376
Future<List<String>?> getExternalStoragePaths({
7477
StorageDirectory? type,
7578
}) async {
76-
return type == null
77-
? <String>[]
78-
: (await _api.getExternalStoragePaths(_convertStorageDirectory(type)))
79-
.cast<String>();
79+
return (await _api.getExternalStoragePaths(_convertStorageDirectory(type)))
80+
.cast<String>();
8081
}
8182

8283
@override

packages/path_provider/path_provider_android/pigeons/messages.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:pigeon/pigeon.dart';
1414
copyrightHeader: 'pigeons/copyright.txt',
1515
))
1616
enum StorageDirectory {
17+
root,
1718
music,
1819
podcasts,
1920
ringtones,

packages/path_provider/path_provider_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: path_provider_android
22
description: Android implementation of the path_provider plugin.
33
repository: https://github.com/flutter/plugins/tree/main/packages/path_provider/path_provider_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+path_provider%22
5-
version: 2.0.15
5+
version: 2.0.16
66

77
environment:
88
sdk: ">=2.14.0 <3.0.0"

packages/path_provider/path_provider_android/test/path_provider_android_test.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ void main() {
8989
});
9090
} // end of for-loop
9191

92-
test('getExternalStoragePaths with null android succeeds', () async {
93-
final List<String>? result =
94-
await pathProvider.getExternalStoragePaths(type: null);
95-
expect(result!.length, 0);
96-
});
97-
9892
test('getDownloadsPath fails', () async {
9993
try {
10094
await pathProvider.getDownloadsPath();

0 commit comments

Comments
 (0)