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

[path_provider] Fixed support for querying the root external storage directory #6036

Merged
merged 1 commit into from
Jun 24, 2022
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
4 changes: 4 additions & 0 deletions packages/path_provider/path_provider_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.16

* Fixes bug with `getExternalStoragePaths(null)`.

## 2.0.15

* Switches the medium from MethodChannels to Pigeon.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
// Autogenerated from Pigeon (v3.2.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package io.flutter.plugins.pathprovider;
Expand All @@ -23,16 +23,17 @@
public class Messages {

public enum StorageDirectory {
music(0),
podcasts(1),
ringtones(2),
alarms(3),
notifications(4),
pictures(5),
movies(6),
downloads(7),
dcim(8),
documents(9);
root(0),
music(1),
podcasts(2),
ringtones(3),
alarms(4),
notifications(5),
pictures(6),
movies(7),
downloads(8),
dcim(9),
documents(10);

private int index;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ private List<String> getPathProviderExternalCacheDirectories() {

private String getStorageDirectoryString(@NonNull Messages.StorageDirectory directory) {
switch (directory) {
case root:
return null;
case music:
return "music";
case podcasts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void main() {
final List<String>? directories =
await provider.getExternalStoragePaths(type: type);
expect(directories, isNotNull);
expect(directories, isNotEmpty);
for (final String result in directories!) {
_verifySampleFile(result, '$type');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
// Autogenerated from Pigeon (v3.2.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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
// @dart = 2.12
Expand All @@ -12,6 +12,7 @@ import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer;
import 'package:flutter/services.dart';

enum StorageDirectory {
root,
music,
podcasts,
ringtones,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
import 'messages.g.dart' as messages;

messages.StorageDirectory _convertStorageDirectory(StorageDirectory directory) {
messages.StorageDirectory _convertStorageDirectory(
StorageDirectory? directory) {
switch (directory) {
case null:
return messages.StorageDirectory.root;
case StorageDirectory.music:
return messages.StorageDirectory.music;
case StorageDirectory.podcasts:
Expand Down Expand Up @@ -73,10 +76,8 @@ class PathProviderAndroid extends PathProviderPlatform {
Future<List<String>?> getExternalStoragePaths({
StorageDirectory? type,
}) async {
return type == null
? <String>[]
: (await _api.getExternalStoragePaths(_convertStorageDirectory(type)))
.cast<String>();
return (await _api.getExternalStoragePaths(_convertStorageDirectory(type)))
.cast<String>();
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:pigeon/pigeon.dart';
copyrightHeader: 'pigeons/copyright.txt',
))
enum StorageDirectory {
root,
music,
podcasts,
ringtones,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: path_provider_android
description: Android implementation of the path_provider plugin.
repository: https://github.com/flutter/plugins/tree/main/packages/path_provider/path_provider_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+path_provider%22
version: 2.0.15
version: 2.0.16

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ void main() {
});
} // end of for-loop

test('getExternalStoragePaths with null android succeeds', () async {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was asserting bad behavior, null should have been passed down to Android.

final List<String>? result =
await pathProvider.getExternalStoragePaths(type: null);
expect(result!.length, 0);
});

test('getDownloadsPath fails', () async {
try {
await pathProvider.getDownloadsPath();
Expand Down