Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[path_provider] Add getApplicationCachePath() #4483

Merged
merged 27 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2b82ed0
[path_provider] Add getApplicationCachePath()
jpnurmi Jul 15, 2023
2c87239
Remove hand-made **/pubspec overrides.yaml
jpnurmi Jul 24, 2023
e0cf6f3
Run flutter_plugin_tools.dart make-deps-path-based
jpnurmi Jul 24, 2023
6c60be1
Remove bogus platform checks from the example
jpnurmi Jul 24, 2023
0f2a87b
Remove unnecessary indirection in the Android plugin
jpnurmi Jul 24, 2023
890edb2
Clean up PathProviderLinux.getApplicationCachePath()
jpnurmi Jul 24, 2023
0cddfa8
Test that PathProviderPlatform.getApplicationCachePath() throws
jpnurmi Jul 24, 2023
ee3666a
De-duplicate _createApplicationSubdirectory()
jpnurmi Jul 24, 2023
72977d5
Remove StorageDirectory.cache
jpnurmi Jul 24, 2023
dacf2be
Fix typo
jpnurmi Jul 24, 2023
47501be
Merge branch 'main' into app-cache-path
jpnurmi Jul 24, 2023
b8b25c9
Try re-running flutter_plugin_tools.dart make-deps-path-based
jpnurmi Jul 24, 2023
06f69b8
Revert "Try re-running flutter_plugin_tools.dart make-deps-path-based"
jpnurmi Jul 24, 2023
517ddb2
Override example deps
jpnurmi Jul 25, 2023
971fb72
Run flutter_plugin_tools.dart format
jpnurmi Jul 25, 2023
040c091
folderID -> folderId
jpnurmi Jul 31, 2023
a7bf3b8
Merge remote-tracking branch 'upstream/main' into app-cache-path
jpnurmi Jul 31, 2023
1a154db
Remove dependency overrides
jpnurmi Jul 31, 2023
856a103
Bump path_provider_platform_interface to ^2.1.0
jpnurmi Jul 31, 2023
1223487
Revert changes to shared_preferences_xxx
jpnurmi Jul 31, 2023
8edccf8
Temporarily override path_provider platform packages
jpnurmi Jul 31, 2023
dd52d64
Merge remote-tracking branch 'upstream/main' into app-cache-path
jpnurmi Aug 3, 2023
e3c9b96
Update README.md: supported platforms and paths
jpnurmi Aug 3, 2023
da8b54e
Remove overrides
jpnurmi Aug 3, 2023
c3acbeb
Bump versions
jpnurmi Aug 3, 2023
5cae273
Fix path_provider_foundation/example/pubspec.yaml
jpnurmi Aug 3, 2023
bf2bea7
Merge branch 'main' into app-cache-path
jpnurmi Aug 5, 2023
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
3 changes: 2 additions & 1 deletion packages/path_provider/path_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.1.0

* Adds getApplicationCachePath() for storing app-specific cache files.
* Updates minimum supported macOS version to 10.14.
* Updates minimum supported SDK version to Flutter 3.3/Dart 2.18.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ 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();
Expand Down
30 changes: 30 additions & 0 deletions packages/path_provider/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,29 @@ class _MyHomePageState extends State<MyHomePage> {
),
],
),
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
onPressed: Platform.isLinux ||
Platform.isMacOS ||
Platform.isWindows
jpnurmi marked this conversation as resolved.
Show resolved Hide resolved
? _requestAppCacheDirectory
: null,
child: Text(
Platform.isAndroid
jpnurmi marked this conversation as resolved.
Show resolved Hide resolved
? 'Application Cache Directory unavailable'
: 'Get Application Cache Directory',
),
),
),
FutureBuilder<Directory?>(
future: _appCacheDirectory,
builder: _buildDirectory,
),
],
),
Column(
children: <Widget>[
Padding(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependency_overrides:
jpnurmi marked this conversation as resolved.
Show resolved Hide resolved
path_provider_platform_interface:
path: ../../path_provider_platform_interface
path_provider_linux:
path: ../../path_provider_linux
path_provider_foundation:
path: ../../path_provider_foundation
path_provider_windows:
path: ../../path_provider_windows
21 changes: 19 additions & 2 deletions packages/path_provider/path_provider/lib/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ Future<Directory> getLibraryDirectory() async {
/// Path to a directory where the application may place data that is
/// user-generated, or that cannot otherwise be recreated by your application.
///
/// Consider using another path, such as [getApplicationSupportDirectory] or
/// [getExternalStorageDirectory], if the data is not user-generated.
/// Consider using another path, such as [getApplicationSupportDirectory],
/// [getApplicationCacheDirectory], or [getExternalStorageDirectory], if the
/// data is not user-generated.
///
/// Example implementations:
/// - `NSDocumentDirectory` on iOS and macOS.
Expand All @@ -125,6 +126,22 @@ Future<Directory> getApplicationDocumentsDirectory() async {
return Directory(path);
}

/// Path to a directory where the application may place application-specific
/// cache files.
///
/// If this directory does not exist, it is created automatically.
///
/// Throws a [MissingPlatformDirectoryException] if the system is unable to
/// provide the directory.
Future<Directory> getApplicationCacheDirectory() async {
final String? path = await _platform.getApplicationCachePath();
if (path == null) {
throw MissingPlatformDirectoryException(
'Unable to get application cache directory');
}
return Directory(path);
}

/// Path to a directory where the application may access top level storage.
///
/// Example implementation:
Expand Down
2 changes: 1 addition & 1 deletion packages/path_provider/path_provider/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: path_provider
description: Flutter plugin for getting commonly used locations on host platform file systems, such as the temp and app data directories.
repository: https://github.com/flutter/packages/tree/main/packages/path_provider/path_provider
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+path_provider%22
version: 2.0.15
version: 2.1.0

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
3 changes: 3 additions & 0 deletions packages/path_provider/path_provider/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependency_overrides:
path_provider_platform_interface:
path: ../path_provider_platform_interface
3 changes: 2 additions & 1 deletion packages/path_provider/path_provider_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.1.0

* Adds getApplicationCachePath() for storing app-specific cache files.
* Updates minimum supported SDK version to Flutter 3.3/Dart 2.18.

## 2.0.27
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v9.2.4), do not edit directly.
// Autogenerated from Pigeon (v9.2.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package io.flutter.plugins.pathprovider;
Expand All @@ -13,8 +13,14 @@
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MessageCodec;
import io.flutter.plugin.common.StandardMessageCodec;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** Generated class from Pigeon. */
@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression", "serial"})
Expand All @@ -29,7 +35,8 @@ public static class FlutterError extends RuntimeException {
/** The error details. Must be a datatype supported by the api codec. */
public final Object details;

public FlutterError(@NonNull String code, @Nullable String message, @Nullable Object details) {
public FlutterError(@NonNull String code, @Nullable String message, @Nullable Object details)
{
super(message);
this.code = code;
this.details = details;
Expand All @@ -48,7 +55,7 @@ protected static ArrayList<Object> wrapError(@NonNull Throwable exception) {
errorList.add(exception.toString());
errorList.add(exception.getClass().getSimpleName());
errorList.add(
"Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception));
"Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception));
}
return errorList;
}
Expand All @@ -64,7 +71,8 @@ public enum StorageDirectory {
MOVIES(7),
DOWNLOADS(8),
DCIM(9),
DOCUMENTS(10);
DOCUMENTS(10),
CACHE(11);

final int index;

Expand All @@ -75,48 +83,47 @@ private StorageDirectory(final int index) {
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface PathProviderApi {

@Nullable
@Nullable
String getTemporaryPath();

@Nullable
@Nullable
String getApplicationSupportPath();

@Nullable
@Nullable
String getApplicationDocumentsPath();

@Nullable
@Nullable
String getApplicationCachePath();

@Nullable
String getExternalStoragePath();

@NonNull
@NonNull
List<String> getExternalCachePaths();

@NonNull
@NonNull
List<String> getExternalStoragePaths(@NonNull StorageDirectory directory);

/** The codec used by PathProviderApi. */
static @NonNull MessageCodec<Object> getCodec() {
return new StandardMessageCodec();
}
/**
* Sets up an instance of `PathProviderApi` to handle messages through the `binaryMessenger`.
*/
/**Sets up an instance of `PathProviderApi` to handle messages through the `binaryMessenger`. */
static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProviderApi api) {
{
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getTemporaryPath",
getCodec(),
taskQueue);
binaryMessenger, "dev.flutter.pigeon.PathProviderApi.getTemporaryPath", getCodec(), taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
try {
String output = api.getTemporaryPath();
wrapped.add(0, output);
} catch (Throwable exception) {
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
Expand All @@ -130,18 +137,16 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProvid
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getApplicationSupportPath",
getCodec(),
taskQueue);
binaryMessenger, "dev.flutter.pigeon.PathProviderApi.getApplicationSupportPath", getCodec(), taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
try {
String output = api.getApplicationSupportPath();
wrapped.add(0, output);
} catch (Throwable exception) {
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
Expand All @@ -155,18 +160,16 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProvid
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getApplicationDocumentsPath",
getCodec(),
taskQueue);
binaryMessenger, "dev.flutter.pigeon.PathProviderApi.getApplicationDocumentsPath", getCodec(), taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
try {
String output = api.getApplicationDocumentsPath();
wrapped.add(0, output);
} catch (Throwable exception) {
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
Expand All @@ -180,18 +183,39 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProvid
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getExternalStoragePath",
getCodec(),
taskQueue);
binaryMessenger, "dev.flutter.pigeon.PathProviderApi.getApplicationCachePath", getCodec(), taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
try {
String output = api.getApplicationCachePath();
wrapped.add(0, output);
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
{
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.PathProviderApi.getExternalStoragePath", getCodec(), taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
try {
String output = api.getExternalStoragePath();
wrapped.add(0, output);
} catch (Throwable exception) {
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
Expand All @@ -205,18 +229,16 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProvid
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getExternalCachePaths",
getCodec(),
taskQueue);
binaryMessenger, "dev.flutter.pigeon.PathProviderApi.getExternalCachePaths", getCodec(), taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
try {
List<String> output = api.getExternalCachePaths();
wrapped.add(0, output);
} catch (Throwable exception) {
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
Expand All @@ -230,21 +252,18 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PathProvid
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths",
getCodec(),
taskQueue);
binaryMessenger, "dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths", getCodec(), taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
StorageDirectory directoryArg =
args.get(0) == null ? null : StorageDirectory.values()[(int) args.get(0)];
StorageDirectory directoryArg = args.get(0) == null ? null : StorageDirectory.values()[(int) args.get(0)];
try {
List<String> output = api.getExternalStoragePaths(directoryArg);
wrapped.add(0, output);
} catch (Throwable exception) {
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
Expand Down
Loading