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
6 changes: 6 additions & 0 deletions packages/path_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.2.0

* On Android, `getApplicationSupportDirectory` is now supported using `getFilesDir`.
* `getExternalStorageDirectory` 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();
}
}
7 changes: 3 additions & 4 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 All @@ -58,7 +57,7 @@ Future<Directory> getApplicationSupportDirectory() async {
/// [getApplicationSupportDirectory] instead if the data is not user-generated.
///
/// On Android, this uses the `getDataDirectory` API on the context. Consider
/// using getExternalStorageDirectory instead if data is intended to be visible
/// using [getExternalStorageDirectory] instead if data is intended to be visible
/// to the user.
Future<Directory> getApplicationDocumentsDirectory() async {
final String 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