Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Pods/
ServiceDefinitions.json
xcuserdata/
*.xcworkspace
**/DerivedData/

local.properties
keystore.properties
Expand Down
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 @@
## 1.3.0

* Added iOS-only support for `getLibraryDirectory`.
* Update integration tests and example test.
* Update example app UI to use a `ListView` show the list of content.
* Update .gitignore to include Xcode build output folder `**/DerivedData/`

## 1.2.2

* Correct the integration test for Android's `getApplicationSupportDirectory` call.
Expand Down
106 changes: 49 additions & 57 deletions packages/path_provider/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
Future<Directory> _tempDirectory;
Future<Directory> _appSupportDirectory;
Future<Directory> _appLibraryDirectory;
Future<Directory> _appDocumentsDirectory;
Future<Directory> _externalDocumentsDirectory;

Expand Down Expand Up @@ -72,6 +73,12 @@ class _MyHomePageState extends State<MyHomePage> {
});
}

void _requestAppLibraryDirectory() {
setState(() {
_appLibraryDirectory = getLibraryDirectory();
});
}

void _requestExternalStorageDirectory() {
setState(() {
_externalDocumentsDirectory = getExternalStorageDirectory();
Expand All @@ -85,70 +92,55 @@ class _MyHomePageState extends State<MyHomePage> {
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
child: ListView(
children: <Widget>[
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: RaisedButton(
child: const Text('Get Temporary Directory'),
onPressed: _requestTempDirectory,
),
),
],
),
Expanded(
child: FutureBuilder<Directory>(
future: _tempDirectory, builder: _buildDirectory),
),
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: RaisedButton(
child: const Text('Get Application Documents Directory'),
onPressed: _requestAppDocumentsDirectory,
),
),
],
Padding(
padding: const EdgeInsets.all(16.0),
child: RaisedButton(
child: const Text('Get Temporary Directory'),
onPressed: _requestTempDirectory,
),
),
Expanded(
child: FutureBuilder<Directory>(
future: _appDocumentsDirectory, builder: _buildDirectory),
FutureBuilder<Directory>(
future: _tempDirectory, builder: _buildDirectory),
Padding(
padding: const EdgeInsets.all(16.0),
child: RaisedButton(
child: const Text('Get Application Documents Directory'),
onPressed: _requestAppDocumentsDirectory,
),
),
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: RaisedButton(
child: const Text('Get Application Support Directory'),
onPressed: _requestAppSupportDirectory,
),
),
],
FutureBuilder<Directory>(
future: _appDocumentsDirectory, builder: _buildDirectory),
Padding(
padding: const EdgeInsets.all(16.0),
child: RaisedButton(
child: const Text('Get Application Support Directory'),
onPressed: _requestAppSupportDirectory,
),
),
Expanded(
child: FutureBuilder<Directory>(
future: _appSupportDirectory, builder: _buildDirectory),
FutureBuilder<Directory>(
future: _appSupportDirectory, builder: _buildDirectory),
Padding(
padding: const EdgeInsets.all(16.0),
child: RaisedButton(
child: const Text('Get Application Library Directory'),
onPressed: _requestAppLibraryDirectory,
),
),
Column(children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: RaisedButton(
child: Text(
'${Platform.isIOS ? "External directories are unavailable " "on iOS" : "Get External Storage Directory"}'),
onPressed:
Platform.isIOS ? null : _requestExternalStorageDirectory,
),
FutureBuilder<Directory>(
future: _appLibraryDirectory, builder: _buildDirectory),
Padding(
padding: const EdgeInsets.all(16.0),
child: RaisedButton(
child: Text(
'${Platform.isIOS ? "External directories are unavailable " "on iOS" : "Get External Storage Directory"}'),
onPressed:
Platform.isIOS ? null : _requestExternalStorageDirectory,
),
]),
Expanded(
child: FutureBuilder<Directory>(
future: _externalDocumentsDirectory,
builder: _buildDirectory),
),
FutureBuilder<Directory>(
future: _externalDocumentsDirectory, builder: _buildDirectory)
],
),
),
Expand Down
15 changes: 15 additions & 0 deletions packages/path_provider/example/test_driver/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ void main() {
file.deleteSync();
});

test('getLibraryDirectory', () async {
if (Platform.isIOS) {
final Directory result = await getLibraryDirectory();
final String uuid = Uuid().v1();
final File file = File('${result.path}/$uuid.txt');
file.writeAsStringSync('Hello world!');
expect(file.readAsStringSync(), 'Hello world!');
expect(result.listSync(), isNotEmpty);
file.deleteSync();
} else if (Platform.isAndroid) {
final Future<Directory> result = getLibraryDirectory();
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
}
});

test('getExternalStorageDirectory', () async {
if (Platform.isIOS) {
final Future<Directory> result = getExternalStorageDirectory();
Expand Down
6 changes: 6 additions & 0 deletions packages/path_provider/ios/Classes/PathProviderPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
} else {
result(path);
}
} else if ([@"getLibraryDirectory" isEqualToString:call.method]) {
result([self getLibraryDirectory]);
} else {
result(FlutterMethodNotImplemented);
}
Expand All @@ -60,4 +62,8 @@ + (NSString*)getApplicationSupportDirectory {
return GetDirectoryOfType(NSApplicationSupportDirectory);
}

+ (NSString*)getLibraryDirectory {
return GetDirectoryOfType(NSLibraryDirectory);
}

@end
11 changes: 11 additions & 0 deletions packages/path_provider/lib/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ Future<Directory> getApplicationSupportDirectory() async {
return Directory(path);
}

/// Path to the directory where application can store files that are persistent,
/// backed up, and not visible to the user, such as sqlite.db.
Future<Directory> getLibraryDirectory() async {
final String path =
await _channel.invokeMethod<String>('getLibraryDirectory');
if (path == null) {
return null;
}
return Directory(path);
}

/// Path to a directory where the application may place data that is
/// user-generated, or that cannot otherwise be recreated by your application.
///
Expand Down
2 changes: 1 addition & 1 deletion packages/path_provider/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for getting commonly used locations on the Android &
iOS file systems, such as the temp and app data directories.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider
version: 1.2.2
version: 1.3.0

flutter:
plugin:
Expand Down
36 changes: 36 additions & 0 deletions packages/path_provider/test/path_provider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ void main() {
expect(directory, isNull);
});

test('getApplicationSupportDirectory test', () async {
response = null;
final Directory directory = await getApplicationSupportDirectory();
expect(
log,
<Matcher>[
isMethodCall('getApplicationSupportDirectory', arguments: null)
],
);
expect(directory, isNull);
});

test('getExternalStorageDirectory test', () async {
response = null;
final Directory directory = await getExternalStorageDirectory();
Expand All @@ -74,6 +86,16 @@ void main() {
expect(directory, isNull);
});

test('getLibraryDirectory test', () async {
response = null;
final Directory directory = await getLibraryDirectory();
expect(
log,
<Matcher>[isMethodCall('getLibraryDirectory', arguments: null)],
);
expect(directory, isNull);
});

test('getExternalStorageDirectory iOS test', () async {
setMockPathProviderPlatform(FakePlatform(operatingSystem: 'ios'));

Expand Down Expand Up @@ -107,6 +129,20 @@ void main() {
expect(directory.path, equals(fakePath));
});

test('ApplicationSupportDirectory path test', () async {
final String fakePath = "/foo/bar/baz";
response = fakePath;
final Directory directory = await getApplicationSupportDirectory();
expect(directory.path, equals(fakePath));
});

test('ApplicationLibraryDirectory path test', () async {
final String fakePath = "/foo/bar/baz";
response = fakePath;
final Directory directory = await getLibraryDirectory();
expect(directory.path, equals(fakePath));
});

test('ExternalStorageDirectory path test', () async {
final String fakePath = "/foo/bar/baz";
response = fakePath;
Expand Down