mirror of
https://github.com/flutter/packages.git
synced 2025-06-28 22:02:38 +08:00
[path_provider_platform_interface] Add getApplicationCachePath() (#4614)
Platform interface changes split out from #4483. /cc @stuartmorgan
This commit is contained in:
@ -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.
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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) {
|
||||
|
@ -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"
|
||||
|
@ -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';
|
||||
@ -39,6 +40,8 @@ void main() {
|
||||
return kLibraryPath;
|
||||
case 'getApplicationDocumentsDirectory':
|
||||
return kApplicationDocumentsPath;
|
||||
case 'getApplicationCacheDirectory':
|
||||
return kApplicationCachePath;
|
||||
case 'getExternalStorageDirectories':
|
||||
return <String>[kExternalStoragePaths];
|
||||
case 'getExternalCacheDirectories':
|
||||
@ -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();
|
||||
|
@ -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 {}
|
Reference in New Issue
Block a user