From caa47b8bc7daf0e0433eac21baac4bf28221bc28 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Tue, 24 Sep 2024 15:18:25 +0900 Subject: [PATCH] [path_provider] Update path_provider to 2.1.4 * Update path_provider to 2.1.4. * Update path_provider_platform_interface to 2.1.2. * Adds getApplicationCachePath() for storing app-specific cache files. * Update minimum Flutter and Dart version to 3.19 and 3.3. --- packages/path_provider/CHANGELOG.md | 7 ++++ packages/path_provider/README.md | 5 ++- .../integration_test/path_provider_test.dart | 38 +++++++++++++++---- packages/path_provider/example/lib/main.dart | 24 ++++++++++++ packages/path_provider/example/pubspec.yaml | 6 +-- .../lib/path_provider_tizen.dart | 3 ++ packages/path_provider/pubspec.yaml | 8 ++-- 7 files changed, 74 insertions(+), 17 deletions(-) diff --git a/packages/path_provider/CHANGELOG.md b/packages/path_provider/CHANGELOG.md index 4148d8f90..773b912ff 100644 --- a/packages/path_provider/CHANGELOG.md +++ b/packages/path_provider/CHANGELOG.md @@ -1,3 +1,10 @@ +## 2.2.0 + +* Update path_provider to 2.1.4. +* Update path_provider_platform_interface to 2.1.2. +* Adds getApplicationCachePath() for storing app-specific cache files. +* Update minimum Flutter and Dart version to 3.19 and 3.3. + ## 2.1.1 * Fix new lint warnings. diff --git a/packages/path_provider/README.md b/packages/path_provider/README.md index 45c2ab4ad..2527cb8fb 100644 --- a/packages/path_provider/README.md +++ b/packages/path_provider/README.md @@ -10,8 +10,8 @@ This package is not an _endorsed_ implementation of `path_provider`. Therefore, ```yaml dependencies: - path_provider: ^2.0.7 - path_provider_tizen: ^2.1.1 + path_provider: ^2.1.4 + path_provider_tizen: ^2.2.0 ``` Then you can import `path_provider` in your Dart code: @@ -28,6 +28,7 @@ For detailed usage, see https://pub.dev/packages/path_provider#usage. - [x] `getApplicationSupportDirectory` (returns the app's data directory path) - [ ] `getLibraryDirectory` (iOS-only) - [x] `getApplicationDocumentsDirectory` (returns the app's data directory path) +- [x] `getApplicationCachePath` (returns the app's cache directory path) - [x] `getExternalStorageDirectory` (requires an SD card) - [x] `getExternalCacheDirectories` (requires an SD card) - [x] `getExternalStorageDirectories` (returns shared media library paths such as `/home/owner/media/Music`) diff --git a/packages/path_provider/example/integration_test/path_provider_test.dart b/packages/path_provider/example/integration_test/path_provider_test.dart index bb723d2d8..2c72ae930 100644 --- a/packages/path_provider/example/integration_test/path_provider_test.dart +++ b/packages/path_provider/example/integration_test/path_provider_test.dart @@ -17,7 +17,15 @@ void main() { testWidgets('getApplicationDocumentsDirectory', (WidgetTester tester) async { final Directory result = await getApplicationDocumentsDirectory(); - _verifySampleFile(result, 'applicationDocuments'); + if (Platform.isMacOS) { + // _verifySampleFile causes hangs in driver when sandboxing is disabled + // because the path changes from an app specific directory to + // ~/Documents, which requires additional permissions to access on macOS. + // Instead, validate that a non-empty path was returned. + expect(result.path, isNotEmpty); + } else { + _verifySampleFile(result, 'applicationDocuments'); + } }); testWidgets('getApplicationSupportDirectory', (WidgetTester tester) async { @@ -25,20 +33,25 @@ void main() { _verifySampleFile(result, 'applicationSupport'); }); + testWidgets('getApplicationCacheDirectory', (WidgetTester tester) async { + final Directory result = await getApplicationCacheDirectory(); + _verifySampleFile(result, 'applicationCache'); + }); + testWidgets('getLibraryDirectory', (WidgetTester tester) async { if (Platform.isIOS) { final Directory result = await getLibraryDirectory(); _verifySampleFile(result, 'library'); } else if (Platform.isAndroid) { final Future result = getLibraryDirectory(); - expect(result, throwsA(isInstanceOf())); + await expectLater(result, throwsA(isInstanceOf())); } }); testWidgets('getExternalStorageDirectory', (WidgetTester tester) async { if (Platform.isIOS) { final Future result = getExternalStorageDirectory(); - expect(result, throwsA(isInstanceOf())); + await expectLater(result, throwsA(isInstanceOf())); } else if (Platform.isAndroid) { final Directory? result = await getExternalStorageDirectory(); _verifySampleFile(result, 'externalStorage'); @@ -48,7 +61,7 @@ void main() { testWidgets('getExternalCacheDirectories', (WidgetTester tester) async { if (Platform.isIOS) { final Future?> result = getExternalCacheDirectories(); - expect(result, throwsA(isInstanceOf())); + await expectLater(result, throwsA(isInstanceOf())); } else if (Platform.isAndroid) { final List? directories = await getExternalCacheDirectories(); expect(directories, isNotNull); @@ -62,6 +75,7 @@ void main() { null, StorageDirectory.music, StorageDirectory.podcasts, + StorageDirectory.ringtones, StorageDirectory.alarms, StorageDirectory.notifications, StorageDirectory.pictures, @@ -69,11 +83,12 @@ void main() { ]; for (final StorageDirectory? type in allDirs) { - test('getExternalStorageDirectories (type: $type)', () async { + testWidgets('getExternalStorageDirectories (type: $type)', + (WidgetTester tester) async { if (Platform.isIOS) { final Future?> result = getExternalStorageDirectories(); - expect(result, throwsA(isInstanceOf())); - } else { + await expectLater(result, throwsA(isInstanceOf())); + } else if (Platform.isAndroid) { final List? directories = await getExternalStorageDirectories(type: type); expect(directories, isNotNull); @@ -101,6 +116,13 @@ void _verifySampleFile(Directory? directory, String name) { file.writeAsStringSync('Hello world!'); expect(file.readAsStringSync(), 'Hello world!'); - expect(directory.listSync(), isNotEmpty); + // This check intentionally avoids using Directory.listSync on Android due to + // https://github.com/dart-lang/sdk/issues/54287. + if (Platform.isAndroid) { + expect( + Process.runSync('ls', [directory.path]).stdout, contains(name)); + } else { + expect(directory.listSync(), isNotEmpty); + } file.deleteSync(); } diff --git a/packages/path_provider/example/lib/main.dart b/packages/path_provider/example/lib/main.dart index 2863d2d43..fcf0e138a 100644 --- a/packages/path_provider/example/lib/main.dart +++ b/packages/path_provider/example/lib/main.dart @@ -41,6 +41,7 @@ class _MyHomePageState extends State { Future? _appSupportDirectory; Future? _appLibraryDirectory; Future? _appDocumentsDirectory; + Future? _appCacheDirectory; Future? _externalDocumentsDirectory; Future?>? _externalStorageDirectories; Future?>? _externalCacheDirectories; @@ -102,6 +103,12 @@ class _MyHomePageState extends State { }); } + void _requestAppCacheDirectory() { + setState(() { + _appCacheDirectory = getApplicationCacheDirectory(); + }); + } + void _requestExternalStorageDirectory() { setState(() { _externalDocumentsDirectory = getExternalStorageDirectory(); @@ -206,6 +213,23 @@ class _MyHomePageState extends State { ), ], ), + Column( + children: [ + Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + onPressed: _requestAppCacheDirectory, + child: const Text( + 'Get Application Cache Directory', + ), + ), + ), + FutureBuilder( + future: _appCacheDirectory, + builder: _buildDirectory, + ), + ], + ), Column( children: [ Padding( diff --git a/packages/path_provider/example/pubspec.yaml b/packages/path_provider/example/pubspec.yaml index bbe56c324..1ddb79552 100644 --- a/packages/path_provider/example/pubspec.yaml +++ b/packages/path_provider/example/pubspec.yaml @@ -3,13 +3,13 @@ description: Demonstrates how to use the path_provider_tizen plugin. publish_to: "none" environment: - sdk: ">=3.1.0 <4.0.0" - flutter: ">=3.13.0" + sdk: ^3.3.0 + flutter: ">=3.19.0" dependencies: flutter: sdk: flutter - path_provider: ^2.0.7 + path_provider: ^2.1.4 path_provider_tizen: path: ../ diff --git a/packages/path_provider/lib/path_provider_tizen.dart b/packages/path_provider/lib/path_provider_tizen.dart index 3fda83ef4..3cd9aee10 100644 --- a/packages/path_provider/lib/path_provider_tizen.dart +++ b/packages/path_provider/lib/path_provider_tizen.dart @@ -22,6 +22,9 @@ class PathProviderPlugin extends PathProviderPlatform { @override Future getApplicationDocumentsPath() async => appCommon.getDataPath(); + @override + Future getApplicationCachePath() async => appCommon.getCachePath(); + @override Future getApplicationSupportPath() async => appCommon.getDataPath(); diff --git a/packages/path_provider/pubspec.yaml b/packages/path_provider/pubspec.yaml index 84d174262..c49ecc674 100644 --- a/packages/path_provider/pubspec.yaml +++ b/packages/path_provider/pubspec.yaml @@ -2,11 +2,11 @@ name: path_provider_tizen description: Tizen implementation of the path_provider plugin. homepage: https://github.com/flutter-tizen/plugins repository: https://github.com/flutter-tizen/plugins/tree/master/packages/path_provider -version: 2.1.1 +version: 2.2.0 environment: - sdk: ">=3.1.0 <4.0.0" - flutter: ">=3.13.0" + sdk: ^3.3.0 + flutter: ">=3.19.0" flutter: plugin: @@ -18,5 +18,5 @@ dependencies: ffi: ^2.0.1 flutter: sdk: flutter - path_provider_platform_interface: ^2.0.1 + path_provider_platform_interface: ^2.1.2 tizen_interop: ^0.3.0