Skip to content

Commit

Permalink
[path_provider] Update path_provider to 2.1.4
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
JSUYA committed Sep 24, 2024
1 parent a56f144 commit caa47b8
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 17 deletions.
7 changes: 7 additions & 0 deletions packages/path_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
5 changes: 3 additions & 2 deletions packages/path_provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,41 @@ 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 {
final Directory result = await getApplicationSupportDirectory();
_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<Directory?> result = getLibraryDirectory();
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
await expectLater(result, throwsA(isInstanceOf<UnsupportedError>()));
}
});

testWidgets('getExternalStorageDirectory', (WidgetTester tester) async {
if (Platform.isIOS) {
final Future<Directory?> result = getExternalStorageDirectory();
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
await expectLater(result, throwsA(isInstanceOf<UnsupportedError>()));
} else if (Platform.isAndroid) {
final Directory? result = await getExternalStorageDirectory();
_verifySampleFile(result, 'externalStorage');
Expand All @@ -48,7 +61,7 @@ void main() {
testWidgets('getExternalCacheDirectories', (WidgetTester tester) async {
if (Platform.isIOS) {
final Future<List<Directory>?> result = getExternalCacheDirectories();
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
await expectLater(result, throwsA(isInstanceOf<UnsupportedError>()));
} else if (Platform.isAndroid) {
final List<Directory>? directories = await getExternalCacheDirectories();
expect(directories, isNotNull);
Expand All @@ -62,18 +75,20 @@ void main() {
null,
StorageDirectory.music,
StorageDirectory.podcasts,
StorageDirectory.ringtones,
StorageDirectory.alarms,
StorageDirectory.notifications,
StorageDirectory.pictures,
StorageDirectory.movies,
];

for (final StorageDirectory? type in allDirs) {
test('getExternalStorageDirectories (type: $type)', () async {
testWidgets('getExternalStorageDirectories (type: $type)',
(WidgetTester tester) async {
if (Platform.isIOS) {
final Future<List<Directory>?> result = getExternalStorageDirectories();
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
} else {
await expectLater(result, throwsA(isInstanceOf<UnsupportedError>()));
} else if (Platform.isAndroid) {
final List<Directory>? directories =
await getExternalStorageDirectories(type: type);
expect(directories, isNotNull);
Expand Down Expand Up @@ -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', <String>[directory.path]).stdout, contains(name));
} else {
expect(directory.listSync(), isNotEmpty);
}
file.deleteSync();
}
24 changes: 24 additions & 0 deletions packages/path_provider/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class _MyHomePageState extends State<MyHomePage> {
Future<Directory?>? _appSupportDirectory;
Future<Directory?>? _appLibraryDirectory;
Future<Directory?>? _appDocumentsDirectory;
Future<Directory?>? _appCacheDirectory;
Future<Directory?>? _externalDocumentsDirectory;
Future<List<Directory>?>? _externalStorageDirectories;
Future<List<Directory>?>? _externalCacheDirectories;
Expand Down Expand Up @@ -102,6 +103,12 @@ class _MyHomePageState extends State<MyHomePage> {
});
}

void _requestAppCacheDirectory() {
setState(() {
_appCacheDirectory = getApplicationCacheDirectory();
});
}

void _requestExternalStorageDirectory() {
setState(() {
_externalDocumentsDirectory = getExternalStorageDirectory();
Expand Down Expand Up @@ -206,6 +213,23 @@ class _MyHomePageState extends State<MyHomePage> {
),
],
),
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
onPressed: _requestAppCacheDirectory,
child: const Text(
'Get Application Cache Directory',
),
),
),
FutureBuilder<Directory?>(
future: _appCacheDirectory,
builder: _buildDirectory,
),
],
),
Column(
children: <Widget>[
Padding(
Expand Down
6 changes: 3 additions & 3 deletions packages/path_provider/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ../

Expand Down
3 changes: 3 additions & 0 deletions packages/path_provider/lib/path_provider_tizen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class PathProviderPlugin extends PathProviderPlatform {
@override
Future<String> getApplicationDocumentsPath() async => appCommon.getDataPath();

@override
Future<String> getApplicationCachePath() async => appCommon.getCachePath();

@override
Future<String> getApplicationSupportPath() async => appCommon.getDataPath();

Expand Down
8 changes: 4 additions & 4 deletions packages/path_provider/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

0 comments on commit caa47b8

Please sign in to comment.