Skip to content

Commit 714913e

Browse files
yash1200adsonpleal
authored andcommitted
[path_provider_linux] Migrate to null safety (flutter#3330)
1 parent 6c47eeb commit 714913e

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

packages/path_provider/path_provider_linux/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.0-nullsafety
2+
3+
* Migrate to null safety.
4+
15
## 0.1.1+3
26

37
* Update Flutter SDK constraint.

packages/path_provider/path_provider_linux/example/integration_test/path_provider_test.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,45 @@
44

55
import 'dart:io';
66
import 'package:flutter_test/flutter_test.dart';
7-
import 'package:path_provider/path_provider.dart';
7+
import 'package:path_provider_linux/path_provider_linux.dart';
88
import 'package:integration_test/integration_test.dart';
99

1010
void main() {
1111
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
1212

1313
testWidgets('getTemporaryDirectory', (WidgetTester tester) async {
14-
final Directory result = await getTemporaryDirectory();
14+
final PathProviderLinux provider = PathProviderLinux();
15+
final String result = await provider.getTemporaryPath();
1516
_verifySampleFile(result, 'temporaryDirectory');
1617
});
1718

1819
testWidgets('getDownloadDirectory', (WidgetTester tester) async {
1920
if (!Platform.isLinux) {
2021
return;
2122
}
22-
final Directory result = await getDownloadsDirectory();
23+
final PathProviderLinux provider = PathProviderLinux();
24+
final String result = await provider.getDownloadsPath();
2325
_verifySampleFile(result, 'downloadDirectory');
2426
});
2527

2628
testWidgets('getApplicationDocumentsDirectory', (WidgetTester tester) async {
27-
final Directory result = await getApplicationDocumentsDirectory();
29+
final PathProviderLinux provider = PathProviderLinux();
30+
final String result = await provider.getApplicationDocumentsPath();
2831
_verifySampleFile(result, 'applicationDocuments');
2932
});
3033

3134
testWidgets('getApplicationSupportDirectory', (WidgetTester tester) async {
32-
final Directory result = await getApplicationSupportDirectory();
35+
final PathProviderLinux provider = PathProviderLinux();
36+
final String result = await provider.getApplicationSupportPath();
3337
_verifySampleFile(result, 'applicationSupport');
3438
});
3539
}
3640

37-
/// Verify a file called [name] in [directory] by recreating it with test
41+
/// Verify a file called [name] in [directoryPath] by recreating it with test
3842
/// contents when necessary.
39-
void _verifySampleFile(Directory directory, String name) {
40-
final File file = File('${directory.path}/$name');
43+
void _verifySampleFile(String directoryPath, String name) {
44+
final Directory directory = Directory(directoryPath);
45+
final File file = File('${directory.path}${Platform.pathSeparator}$name');
4146

4247
if (file.existsSync()) {
4348
file.deleteSync();

packages/path_provider/path_provider_linux/example/lib/main.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
22
import 'dart:async';
33

44
import 'package:flutter/services.dart';
5-
import 'package:path_provider/path_provider.dart';
5+
import 'package:path_provider_linux/path_provider_linux.dart';
66

77
void main() async {
88
runApp(MyApp());
@@ -19,6 +19,7 @@ class _MyAppState extends State<MyApp> {
1919
String _downloadsDirectory = 'Unknown';
2020
String _appSupportDirectory = 'Unknown';
2121
String _documentsDirectory = 'Unknown';
22+
final PathProviderLinux _provider = PathProviderLinux();
2223

2324
@override
2425
void initState() {
@@ -34,27 +35,27 @@ class _MyAppState extends State<MyApp> {
3435
String documentsDirectory;
3536
// Platform messages may fail, so we use a try/catch PlatformException.
3637
try {
37-
tempDirectory = (await getTemporaryDirectory()).path;
38+
tempDirectory = await _provider.getTemporaryPath();
3839
} on PlatformException catch (e, stackTrace) {
3940
tempDirectory = 'Failed to get temp directory.';
4041
print('$tempDirectory $e $stackTrace');
4142
}
4243
try {
43-
downloadsDirectory = (await getDownloadsDirectory()).path;
44+
downloadsDirectory = await _provider.getDownloadsPath();
4445
} on PlatformException catch (e, stackTrace) {
4546
downloadsDirectory = 'Failed to get downloads directory.';
4647
print('$downloadsDirectory $e $stackTrace');
4748
}
4849

4950
try {
50-
documentsDirectory = (await getApplicationDocumentsDirectory()).path;
51+
documentsDirectory = await _provider.getApplicationDocumentsPath();
5152
} on PlatformException catch (e, stackTrace) {
5253
documentsDirectory = 'Failed to get documents directory.';
5354
print('$documentsDirectory $e $stackTrace');
5455
}
5556

5657
try {
57-
appSupportDirectory = (await getApplicationSupportDirectory()).path;
58+
appSupportDirectory = await _provider.getApplicationSupportPath();
5859
} on PlatformException catch (e, stackTrace) {
5960
appSupportDirectory = 'Failed to get documents directory.';
6061
print('$appSupportDirectory $e $stackTrace');

packages/path_provider/path_provider_linux/example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies:
99
flutter:
1010
sdk: flutter
1111

12-
path_provider: ^1.6.10
12+
path_provider_linux: any
1313

1414
# The following adds the Cupertino Icons font to your application.
1515
# Use with the CupertinoIcons class for iOS style icons.

packages/path_provider/path_provider_linux/lib/path_provider_linux.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ class PathProviderLinux extends PathProviderPlatform {
1818
}
1919

2020
@override
21-
Future<String> getTemporaryPath() {
21+
Future<String?> getTemporaryPath() {
2222
return Future.value("/tmp");
2323
}
2424

2525
@override
26-
Future<String> getApplicationSupportPath() async {
26+
Future<String?> getApplicationSupportPath() async {
2727
final processName = path.basenameWithoutExtension(
2828
await File('/proc/self/exe').resolveSymbolicLinks());
2929
final directory = Directory(path.join(xdg.dataHome.path, processName));
@@ -35,12 +35,12 @@ class PathProviderLinux extends PathProviderPlatform {
3535
}
3636

3737
@override
38-
Future<String> getApplicationDocumentsPath() {
39-
return Future.value(xdg.getUserDirectory('DOCUMENTS').path);
38+
Future<String?> getApplicationDocumentsPath() {
39+
return Future.value(xdg.getUserDirectory('DOCUMENTS')?.path);
4040
}
4141

4242
@override
43-
Future<String> getDownloadsPath() {
44-
return Future.value(xdg.getUserDirectory('DOWNLOAD').path);
43+
Future<String?> getDownloadsPath() {
44+
return Future.value(xdg.getUserDirectory('DOWNLOAD')?.path);
4545
}
4646
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: path_provider_linux
22
description: linux implementation of the path_provider plugin
3-
version: 0.1.1+3
3+
version: 0.2.0-nullsafety
44
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_linux
55

66
flutter:
@@ -11,17 +11,17 @@ flutter:
1111
pluginClass: none
1212

1313
environment:
14-
sdk: ">=2.1.0 <3.0.0"
14+
sdk: ">=2.12.0-0 <3.0.0"
1515
flutter: ">=1.10.0"
1616

1717
dependencies:
18-
path: ^1.6.4
19-
xdg_directories: ^0.1.0
20-
path_provider_platform_interface: ^1.0.1
18+
path: ^1.8.0-nullsafety.3
19+
xdg_directories: ^0.2.0-nullsafety.1
20+
path_provider_platform_interface: ^2.0.0-nullsafety
2121
flutter:
2222
sdk: flutter
2323

2424
dev_dependencies:
2525
flutter_test:
2626
sdk: flutter
27-
pedantic: ^1.8.0
27+
pedantic: ^1.10.0-nullsafety.3

0 commit comments

Comments
 (0)