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

Commit f9529b2

Browse files
authored
[Path Provider] Migrate platform interface to nnbd (#3249)
1 parent 0f6a1be commit f9529b2

File tree

5 files changed

+47
-38
lines changed

5 files changed

+47
-38
lines changed

packages/path_provider/path_provider_platform_interface/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 2.0.0-nullsafety
2+
3+
* Migrate to null safety.
4+
5+
## 1.0.4
6+
7+
* Remove unused `test` dependency.
8+
19
## 1.0.3
210

311
* Increase upper range of `package:platform` constraint to allow 3.X versions.

packages/path_provider/path_provider_platform_interface/lib/path_provider_platform_interface.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,34 @@ abstract class PathProviderPlatform extends PlatformInterface {
4040

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

4747
/// Path to a directory where the application may place application support
4848
/// files.
49-
Future<String> getApplicationSupportPath() {
49+
Future<String?> getApplicationSupportPath() {
5050
throw UnimplementedError(
5151
'getApplicationSupportPath() has not been implemented.');
5252
}
5353

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

6060
/// Path to a directory where the application may place data that is
6161
/// user-generated, or that cannot otherwise be recreated by your application.
62-
Future<String> getApplicationDocumentsPath() {
62+
Future<String?> getApplicationDocumentsPath() {
6363
throw UnimplementedError(
6464
'getApplicationDocumentsPath() has not been implemented.');
6565
}
6666

6767
/// Path to a directory where the application may access top level storage.
6868
/// The current operating system should be determined before issuing this
6969
/// function call, as this functionality is only available on Android.
70-
Future<String> getExternalStoragePath() {
70+
Future<String?> getExternalStoragePath() {
7171
throw UnimplementedError(
7272
'getExternalStoragePath() has not been implemented.');
7373
}
@@ -76,26 +76,26 @@ abstract class PathProviderPlatform extends PlatformInterface {
7676
/// stored. These paths typically reside on external storage like separate
7777
/// partitions or SD cards. Phones may have multiple storage directories
7878
/// available.
79-
Future<List<String>> getExternalCachePaths() {
79+
Future<List<String>?> getExternalCachePaths() {
8080
throw UnimplementedError(
8181
'getExternalCachePaths() has not been implemented.');
8282
}
8383

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

9696
/// Path to the directory where downloaded files can be stored.
9797
/// This is typically only relevant on desktop operating systems.
98-
Future<String> getDownloadsPath() {
98+
Future<String?> getDownloadsPath() {
9999
throw UnimplementedError('getDownloadsPath() has not been implemented.');
100100
}
101101
}

packages/path_provider/path_provider_platform_interface/lib/src/method_channel_path_provider.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,43 @@ class MethodChannelPathProvider extends PathProviderPlatform {
3030
_platform = platform;
3131
}
3232

33-
Future<String> getTemporaryPath() {
33+
Future<String?> getTemporaryPath() {
3434
return methodChannel.invokeMethod<String>('getTemporaryDirectory');
3535
}
3636

37-
Future<String> getApplicationSupportPath() {
37+
Future<String?> getApplicationSupportPath() {
3838
return methodChannel.invokeMethod<String>('getApplicationSupportDirectory');
3939
}
4040

41-
Future<String> getLibraryPath() {
41+
Future<String?> getLibraryPath() {
4242
if (!_platform.isIOS && !_platform.isMacOS) {
4343
throw UnsupportedError('Functionality only available on iOS/macOS');
4444
}
4545
return methodChannel.invokeMethod<String>('getLibraryDirectory');
4646
}
4747

48-
Future<String> getApplicationDocumentsPath() {
48+
Future<String?> getApplicationDocumentsPath() {
4949
return methodChannel
5050
.invokeMethod<String>('getApplicationDocumentsDirectory');
5151
}
5252

53-
Future<String> getExternalStoragePath() {
53+
Future<String?> getExternalStoragePath() {
5454
if (!_platform.isAndroid) {
5555
throw UnsupportedError('Functionality only available on Android');
5656
}
5757
return methodChannel.invokeMethod<String>('getStorageDirectory');
5858
}
5959

60-
Future<List<String>> getExternalCachePaths() {
60+
Future<List<String>?> getExternalCachePaths() {
6161
if (!_platform.isAndroid) {
6262
throw UnsupportedError('Functionality only available on Android');
6363
}
6464
return methodChannel
6565
.invokeListMethod<String>('getExternalCacheDirectories');
6666
}
6767

68-
Future<List<String>> getExternalStoragePaths({
69-
StorageDirectory type,
68+
Future<List<String>?> getExternalStoragePaths({
69+
StorageDirectory? type,
7070
}) async {
7171
if (!_platform.isAndroid) {
7272
throw UnsupportedError('Functionality only available on Android');
@@ -77,7 +77,7 @@ class MethodChannelPathProvider extends PathProviderPlatform {
7777
);
7878
}
7979

80-
Future<String> getDownloadsPath() {
80+
Future<String?> getDownloadsPath() {
8181
if (!_platform.isMacOS) {
8282
throw UnsupportedError('Functionality only available on macOS');
8383
}

packages/path_provider/path_provider_platform_interface/pubspec.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ description: A common platform interface for the path_provider plugin.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_platform_interface
44
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
55
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
6-
version: 1.0.3
6+
version: 2.0.0-nullsafety
77

88
dependencies:
99
flutter:
1010
sdk: flutter
11-
meta: ^1.0.5
11+
meta: ^1.3.0-nullsafety.3
1212
platform: ">=2.0.0 <4.0.0"
13-
plugin_platform_interface: ^1.0.1
13+
plugin_platform_interface: 1.1.0-nullsafety
1414

1515
dev_dependencies:
1616
flutter_test:
1717
sdk: flutter
18-
pedantic: ^1.8.0
19-
test: any
18+
pedantic: ^1.10.0-nullsafety.1
2019

2120
environment:
22-
sdk: ">=2.1.0 <3.0.0"
23-
flutter: ">=1.10.0 <2.0.0"
21+
sdk: ">=2.12.0-0 <3.0.0"
22+
flutter: ">=1.12.13+hotfix.5 <2.0.0"

packages/path_provider/path_provider_platform_interface/test/method_channel_path_provider_test.dart

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void main() {
1919
const String kDownloadsPath = 'downloadsPath';
2020

2121
group('$MethodChannelPathProvider', () {
22-
MethodChannelPathProvider methodChannelPathProvider;
22+
late MethodChannelPathProvider methodChannelPathProvider;
2323
final List<MethodCall> log = <MethodCall>[];
2424

2525
setUp(() async {
@@ -59,7 +59,7 @@ void main() {
5959
});
6060

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

7070
test('getApplicationSupportPath', () async {
71-
final String path =
71+
final String? path =
7272
await methodChannelPathProvider.getApplicationSupportPath();
7373
expect(
7474
log,
@@ -92,7 +92,7 @@ void main() {
9292
methodChannelPathProvider
9393
.setMockPathProviderPlatform(FakePlatform(operatingSystem: 'ios'));
9494

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

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

115115
test('getApplicationDocumentsPath', () async {
116-
final String path =
116+
final String? path =
117117
await methodChannelPathProvider.getApplicationDocumentsPath();
118118
expect(
119119
log,
@@ -125,13 +125,13 @@ void main() {
125125
});
126126

127127
test('getExternalCachePaths android succeeds', () async {
128-
final List<String> result =
128+
final List<String>? result =
129129
await methodChannelPathProvider.getExternalCachePaths();
130130
expect(
131131
log,
132132
<Matcher>[isMethodCall('getExternalCacheDirectories', arguments: null)],
133133
);
134-
expect(result.length, 1);
134+
expect(result!.length, 1);
135135
expect(result.first, kExternalCachePaths);
136136
});
137137

@@ -147,10 +147,12 @@ void main() {
147147
}
148148
});
149149

150-
for (StorageDirectory type
151-
in StorageDirectory.values + <StorageDirectory>[null]) {
150+
for (StorageDirectory? type in <StorageDirectory?>[
151+
null,
152+
...StorageDirectory.values
153+
]) {
152154
test('getExternalStoragePaths (type: $type) android succeeds', () async {
153-
final List<String> result =
155+
final List<String>? result =
154156
await methodChannelPathProvider.getExternalStoragePaths(type: type);
155157
expect(
156158
log,
@@ -162,7 +164,7 @@ void main() {
162164
],
163165
);
164166

165-
expect(result.length, 1);
167+
expect(result!.length, 1);
166168
expect(result.first, kExternalStoragePaths);
167169
});
168170

@@ -182,7 +184,7 @@ void main() {
182184
test('getDownloadsPath macos succeeds', () async {
183185
methodChannelPathProvider
184186
.setMockPathProviderPlatform(FakePlatform(operatingSystem: 'macos'));
185-
final String result = await methodChannelPathProvider.getDownloadsPath();
187+
final String? result = await methodChannelPathProvider.getDownloadsPath();
186188
expect(
187189
log,
188190
<Matcher>[isMethodCall('getDownloadsDirectory', arguments: null)],

0 commit comments

Comments
 (0)