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 3 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/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.2.0

* Android: `getApplicationSupportDirectory` enabled by using `getFilesDir`.

@collinjackson collinjackson Jul 23, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Android: `getApplicationSupportDirectory` enabled by using `getFilesDir`.
* On Android, `getApplicationSupportDirectory` is now supported and uses `getFilesDir`.
* `getStorageDirectory` now returns `null` instead of throwing an exception if no external files directory is available.


## 1.1.2

* `getExternalStorageDirectory` now uses `getExternalFilesDir` on Android.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.util.PathUtils;
import java.io.File;

public class PathProviderPlugin implements MethodCallHandler {
private final Registrar mRegistrar;
Expand Down Expand Up @@ -37,6 +38,8 @@ public void onMethodCall(MethodCall call, Result result) {
case "getStorageDirectory":
result.success(getPathProviderStorageDirectory());
break;
case "getApplicationSupportDirectory":
result.success(getApplicationSupportDirectory());
default:
result.notImplemented();
}
Expand All @@ -46,11 +49,19 @@ private String getPathProviderTemporaryDirectory() {
return mRegistrar.context().getCacheDir().getPath();
}

private String getApplicationSupportDirectory() {
return PathUtils.getFilesDir(mRegistrar.context());
}

private String getPathProviderApplicationDocumentsDirectory() {
return PathUtils.getDataDirectory(mRegistrar.context());
}

private String getPathProviderStorageDirectory() {
return mRegistrar.context().getExternalFilesDir(null).getAbsolutePath();
final File dir = mRegistrar.context().getExternalFilesDir(null);
if (dir == null) {
return null;
}
return dir.getAbsolutePath();
}
}
5 changes: 2 additions & 3 deletions packages/path_provider/lib/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ Future<Directory> getTemporaryDirectory() async {
/// On iOS, this uses the `NSApplicationSupportDirectory` API.
/// If this directory does not exist, it is created automatically.
///
/// On Android, this function throws an [UnsupportedError].
/// On Android, this function uses the `getFilesDir` API on the context.
Future<Directory> getApplicationSupportDirectory() async {
if (!Platform.isIOS)
throw UnsupportedError("getApplicationSupportDirectory requires iOS");
final String path =
await _channel.invokeMethod<String>('getApplicationSupportDirectory');
if (path == null) {
return null;
}

return Directory(path);
}

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 <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider
version: 1.1.2
version: 1.2.0

flutter:
plugin:
Expand Down