Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[Path Provider] Migrate platform interface to nnbd #3249

Merged
merged 4 commits into from
Nov 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.0.0-nullsafety

* Migrate to null safety.

## 1.0.4

* Remove unused `test` dependency.

## 1.0.3

* Increase upper range of `package:platform` constraint to allow 3.X versions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,34 @@ abstract class PathProviderPlatform extends PlatformInterface {

/// Path to the temporary directory on the device that is not backed up and is
/// suitable for storing caches of downloaded files.
Future<String> getTemporaryPath() {
Future<String?> getTemporaryPath() {
throw UnimplementedError('getTemporaryPath() has not been implemented.');
}

/// Path to a directory where the application may place application support
/// files.
Future<String> getApplicationSupportPath() {
Future<String?> getApplicationSupportPath() {
throw UnimplementedError(
'getApplicationSupportPath() has not been implemented.');
}

/// Path to the directory where application can store files that are persistent,
/// backed up, and not visible to the user, such as sqlite.db.
Future<String> getLibraryPath() {
Future<String?> getLibraryPath() {
throw UnimplementedError('getLibraryPath() has not been implemented.');
}

/// Path to a directory where the application may place data that is
/// user-generated, or that cannot otherwise be recreated by your application.
Future<String> getApplicationDocumentsPath() {
Future<String?> getApplicationDocumentsPath() {
throw UnimplementedError(
'getApplicationDocumentsPath() 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.
Future<String> getExternalStoragePath() {
Future<String?> getExternalStoragePath() {
throw UnimplementedError(
'getExternalStoragePath() has not been implemented.');
}
Expand All @@ -76,26 +76,26 @@ abstract class PathProviderPlatform extends PlatformInterface {
/// stored. These paths typically reside on external storage like separate
/// partitions or SD cards. Phones may have multiple storage directories
/// available.
Future<List<String>> getExternalCachePaths() {
Future<List<String>?> getExternalCachePaths() {
throw UnimplementedError(
'getExternalCachePaths() has not been implemented.');
}

/// Paths to directories where application specific data can be stored.
/// These paths typically reside on external storage like separate partitions
/// or SD cards. Phones may have multiple storage directories available.
Future<List<String>> getExternalStoragePaths({
Future<List<String>?> getExternalStoragePaths({
/// Optional parameter. See [StorageDirectory] for more informations on
/// how this type translates to Android storage directories.
StorageDirectory type,
StorageDirectory? type,
}) {
throw UnimplementedError(
'getExternalStoragePaths() has not been implemented.');
}

/// Path to the directory where downloaded files can be stored.
/// This is typically only relevant on desktop operating systems.
Future<String> getDownloadsPath() {
Future<String?> getDownloadsPath() {
throw UnimplementedError('getDownloadsPath() has not been implemented.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,43 @@ class MethodChannelPathProvider extends PathProviderPlatform {
_platform = platform;
}

Future<String> getTemporaryPath() {
Future<String?> getTemporaryPath() {
return methodChannel.invokeMethod<String>('getTemporaryDirectory');
}

Future<String> getApplicationSupportPath() {
Future<String?> getApplicationSupportPath() {
return methodChannel.invokeMethod<String>('getApplicationSupportDirectory');
}

Future<String> getLibraryPath() {
Future<String?> getLibraryPath() {
if (!_platform.isIOS && !_platform.isMacOS) {
throw UnsupportedError('Functionality only available on iOS/macOS');
}
return methodChannel.invokeMethod<String>('getLibraryDirectory');
}

Future<String> getApplicationDocumentsPath() {
Future<String?> getApplicationDocumentsPath() {
return methodChannel
.invokeMethod<String>('getApplicationDocumentsDirectory');
}

Future<String> getExternalStoragePath() {
Future<String?> getExternalStoragePath() {
if (!_platform.isAndroid) {
throw UnsupportedError('Functionality only available on Android');
}
return methodChannel.invokeMethod<String>('getStorageDirectory');
}

Future<List<String>> getExternalCachePaths() {
Future<List<String>?> getExternalCachePaths() {
if (!_platform.isAndroid) {
throw UnsupportedError('Functionality only available on Android');
}
return methodChannel
.invokeListMethod<String>('getExternalCacheDirectories');
}

Future<List<String>> getExternalStoragePaths({
StorageDirectory type,
Future<List<String>?> getExternalStoragePaths({
StorageDirectory? type,
}) async {
if (!_platform.isAndroid) {
throw UnsupportedError('Functionality only available on Android');
Expand All @@ -77,7 +77,7 @@ class MethodChannelPathProvider extends PathProviderPlatform {
);
}

Future<String> getDownloadsPath() {
Future<String?> getDownloadsPath() {
if (!_platform.isMacOS) {
throw UnsupportedError('Functionality only available on macOS');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ description: A common platform interface for the path_provider plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_platform_interface
# 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: 1.0.3
version: 2.0.0-nullsafety

dependencies:
flutter:
sdk: flutter
meta: ^1.0.5
meta: ^1.3.0-nullsafety.3
platform: ">=2.0.0 <4.0.0"
plugin_platform_interface: ^1.0.1
plugin_platform_interface: 1.1.0-nullsafety

dev_dependencies:
flutter_test:
sdk: flutter
pedantic: ^1.8.0
test: any
pedantic: ^1.10.0-nullsafety.1

environment:
sdk: ">=2.1.0 <3.0.0"
flutter: ">=1.10.0 <2.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void main() {
const String kDownloadsPath = 'downloadsPath';

group('$MethodChannelPathProvider', () {
MethodChannelPathProvider methodChannelPathProvider;
late MethodChannelPathProvider methodChannelPathProvider;
final List<MethodCall> log = <MethodCall>[];

setUp(() async {
Expand Down Expand Up @@ -59,7 +59,7 @@ void main() {
});

test('getTemporaryPath', () async {
final String path = await methodChannelPathProvider.getTemporaryPath();
final String? path = await methodChannelPathProvider.getTemporaryPath();
expect(
log,
<Matcher>[isMethodCall('getTemporaryDirectory', arguments: null)],
Expand All @@ -68,7 +68,7 @@ void main() {
});

test('getApplicationSupportPath', () async {
final String path =
final String? path =
await methodChannelPathProvider.getApplicationSupportPath();
expect(
log,
Expand All @@ -92,7 +92,7 @@ void main() {
methodChannelPathProvider
.setMockPathProviderPlatform(FakePlatform(operatingSystem: 'ios'));

final String path = await methodChannelPathProvider.getLibraryPath();
final String? path = await methodChannelPathProvider.getLibraryPath();
expect(
log,
<Matcher>[isMethodCall('getLibraryDirectory', arguments: null)],
Expand All @@ -104,7 +104,7 @@ void main() {
methodChannelPathProvider
.setMockPathProviderPlatform(FakePlatform(operatingSystem: 'macos'));

final String path = await methodChannelPathProvider.getLibraryPath();
final String? path = await methodChannelPathProvider.getLibraryPath();
expect(
log,
<Matcher>[isMethodCall('getLibraryDirectory', arguments: null)],
Expand All @@ -113,7 +113,7 @@ void main() {
});

test('getApplicationDocumentsPath', () async {
final String path =
final String? path =
await methodChannelPathProvider.getApplicationDocumentsPath();
expect(
log,
Expand All @@ -125,13 +125,13 @@ void main() {
});

test('getExternalCachePaths android succeeds', () async {
final List<String> result =
final List<String>? result =
await methodChannelPathProvider.getExternalCachePaths();
expect(
log,
<Matcher>[isMethodCall('getExternalCacheDirectories', arguments: null)],
);
expect(result.length, 1);
expect(result!.length, 1);
expect(result.first, kExternalCachePaths);
});

Expand All @@ -147,10 +147,12 @@ void main() {
}
});

for (StorageDirectory type
in StorageDirectory.values + <StorageDirectory>[null]) {
for (StorageDirectory? type in <StorageDirectory?>[
null,
...StorageDirectory.values
]) {
test('getExternalStoragePaths (type: $type) android succeeds', () async {
final List<String> result =
final List<String>? result =
await methodChannelPathProvider.getExternalStoragePaths(type: type);
expect(
log,
Expand All @@ -162,7 +164,7 @@ void main() {
],
);

expect(result.length, 1);
expect(result!.length, 1);
expect(result.first, kExternalStoragePaths);
});

Expand All @@ -182,7 +184,7 @@ void main() {
test('getDownloadsPath macos succeeds', () async {
methodChannelPathProvider
.setMockPathProviderPlatform(FakePlatform(operatingSystem: 'macos'));
final String result = await methodChannelPathProvider.getDownloadsPath();
final String? result = await methodChannelPathProvider.getDownloadsPath();
expect(
log,
<Matcher>[isMethodCall('getDownloadsDirectory', arguments: null)],
Expand Down