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_platform_interface] Add getApplicationCachePath() #4614

Merged
merged 1 commit into from
Jul 31, 2023
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
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.
* Aligns Dart and Flutter SDK constraints.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ abstract class PathProviderPlatform extends PlatformInterface {
'getApplicationDocumentsPath() has not been implemented.');
}

/// Path to a directory where application specific cache data can be stored.
Future<String?> getApplicationCachePath() {
throw UnimplementedError(
'getApplicationCachePath() has not been implemented.');
}

/// Path to a directory where the application may access top level storage.
/// The current operating system should be determined before issuing this
/// function call, as this functionality is only available on Android.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class MethodChannelPathProvider extends PathProviderPlatform {
.invokeMethod<String>('getApplicationDocumentsDirectory');
}

@override
Future<String?> getApplicationCachePath() {
return methodChannel.invokeMethod<String>('getApplicationCacheDirectory');
}

@override
Future<String?> getExternalStoragePath() {
if (!_platform.isAndroid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/path_provider
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+path_provider%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.0.6
version: 2.1.0

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void main() {
const String kApplicationSupportPath = 'applicationSupportPath';
const String kLibraryPath = 'libraryPath';
const String kApplicationDocumentsPath = 'applicationDocumentsPath';
const String kApplicationCachePath = 'applicationCachePath';
const String kExternalCachePaths = 'externalCachePaths';
const String kExternalStoragePaths = 'externalStoragePaths';
const String kDownloadsPath = 'downloadsPath';
Expand All @@ -39,6 +40,8 @@ void main() {
return kLibraryPath;
case 'getApplicationDocumentsDirectory':
return kApplicationDocumentsPath;
case 'getApplicationCacheDirectory':
return kApplicationCachePath;
case 'getExternalStorageDirectories':
return <String>[kExternalStoragePaths];
case 'getExternalCacheDirectories':
Expand Down Expand Up @@ -126,6 +129,18 @@ void main() {
expect(path, kApplicationDocumentsPath);
});

test('getApplicationCachePath succeeds', () async {
final String? result =
await methodChannelPathProvider.getApplicationCachePath();
expect(
log,
<Matcher>[
isMethodCall('getApplicationCacheDirectory', arguments: null)
],
);
expect(result, kApplicationCachePath);
});

test('getExternalCachePaths android succeeds', () async {
final List<String>? result =
await methodChannelPathProvider.getExternalCachePaths();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.

import 'package:flutter_test/flutter_test.dart';
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
import 'package:path_provider_platform_interface/src/method_channel_path_provider.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

group('$PathProviderPlatform', () {
test('$MethodChannelPathProvider is the default instance', () {
expect(PathProviderPlatform.instance, isA<MethodChannelPathProvider>());
});

test('getApplicationCachePath throws unimplemented error', () {
final ExtendsPathProviderPlatform pathProviderPlatform =
ExtendsPathProviderPlatform();

expect(
() => pathProviderPlatform.getApplicationCachePath(),
throwsUnimplementedError,
);
});
});
}

class ExtendsPathProviderPlatform extends PathProviderPlatform {}