diff --git a/packages/path_provider/path_provider_android/CHANGELOG.md b/packages/path_provider/path_provider_android/CHANGELOG.md index 6b1b6611004e..c40c103d5848 100644 --- a/packages/path_provider/path_provider_android/CHANGELOG.md +++ b/packages/path_provider/path_provider_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.16 + +* Fixes bug with `getExternalStoragePaths(null)`. + ## 2.0.15 * Switches the medium from MethodChannels to Pigeon. diff --git a/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/Messages.java b/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/Messages.java index 1e78916ebbc6..47144d4a8fcd 100644 --- a/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/Messages.java +++ b/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/Messages.java @@ -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; @@ -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; diff --git a/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java b/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java index 8a5ff48b6477..7ef82198b22c 100644 --- a/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java +++ b/packages/path_provider/path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java @@ -125,6 +125,8 @@ private List getPathProviderExternalCacheDirectories() { private String getStorageDirectoryString(@NonNull Messages.StorageDirectory directory) { switch (directory) { + case root: + return null; case music: return "music"; case podcasts: diff --git a/packages/path_provider/path_provider_android/example/integration_test/path_provider_test.dart b/packages/path_provider/path_provider_android/example/integration_test/path_provider_test.dart index 0538738ade7e..2be88130b4e7 100644 --- a/packages/path_provider/path_provider_android/example/integration_test/path_provider_test.dart +++ b/packages/path_provider/path_provider_android/example/integration_test/path_provider_test.dart @@ -68,6 +68,7 @@ void main() { final List? directories = await provider.getExternalStoragePaths(type: type); expect(directories, isNotNull); + expect(directories, isNotEmpty); for (final String result in directories!) { _verifySampleFile(result, '$type'); } diff --git a/packages/path_provider/path_provider_android/lib/messages.g.dart b/packages/path_provider/path_provider_android/lib/messages.g.dart index 50009f454ad7..cf095c244b8d 100644 --- a/packages/path_provider/path_provider_android/lib/messages.g.dart +++ b/packages/path_provider/path_provider_android/lib/messages.g.dart @@ -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 @@ -12,6 +12,7 @@ import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer; import 'package:flutter/services.dart'; enum StorageDirectory { + root, music, podcasts, ringtones, diff --git a/packages/path_provider/path_provider_android/lib/path_provider_android.dart b/packages/path_provider/path_provider_android/lib/path_provider_android.dart index 4f08d7af08d4..f5c74f540253 100644 --- a/packages/path_provider/path_provider_android/lib/path_provider_android.dart +++ b/packages/path_provider/path_provider_android/lib/path_provider_android.dart @@ -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: @@ -73,10 +76,8 @@ class PathProviderAndroid extends PathProviderPlatform { Future?> getExternalStoragePaths({ StorageDirectory? type, }) async { - return type == null - ? [] - : (await _api.getExternalStoragePaths(_convertStorageDirectory(type))) - .cast(); + return (await _api.getExternalStoragePaths(_convertStorageDirectory(type))) + .cast(); } @override diff --git a/packages/path_provider/path_provider_android/pigeons/messages.dart b/packages/path_provider/path_provider_android/pigeons/messages.dart index 464166771b0a..96ad6343d3b0 100644 --- a/packages/path_provider/path_provider_android/pigeons/messages.dart +++ b/packages/path_provider/path_provider_android/pigeons/messages.dart @@ -14,6 +14,7 @@ import 'package:pigeon/pigeon.dart'; copyrightHeader: 'pigeons/copyright.txt', )) enum StorageDirectory { + root, music, podcasts, ringtones, diff --git a/packages/path_provider/path_provider_android/pubspec.yaml b/packages/path_provider/path_provider_android/pubspec.yaml index 64b953b2ca07..4c228bbb43bc 100644 --- a/packages/path_provider/path_provider_android/pubspec.yaml +++ b/packages/path_provider/path_provider_android/pubspec.yaml @@ -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" diff --git a/packages/path_provider/path_provider_android/test/path_provider_android_test.dart b/packages/path_provider/path_provider_android/test/path_provider_android_test.dart index 2fe4a51fe5eb..e3011474a2a3 100644 --- a/packages/path_provider/path_provider_android/test/path_provider_android_test.dart +++ b/packages/path_provider/path_provider_android/test/path_provider_android_test.dart @@ -89,12 +89,6 @@ void main() { }); } // end of for-loop - test('getExternalStoragePaths with null android succeeds', () async { - final List? result = - await pathProvider.getExternalStoragePaths(type: null); - expect(result!.length, 0); - }); - test('getDownloadsPath fails', () async { try { await pathProvider.getDownloadsPath();