Skip to content

Commit

Permalink
[path_provider_platform_interface] Add getApplicationCachePath() (flu…
Browse files Browse the repository at this point in the history
…tter#4614)

Platform interface changes split out from flutter#4483.

/cc @stuartmorgan
  • Loading branch information
jpnurmi authored Jul 31, 2023
1 parent 9e21922 commit a8ea4d6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
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 {}

0 comments on commit a8ea4d6

Please sign in to comment.