From cb4ce410c97f88e59c648ac9757e49c9870cdc4a Mon Sep 17 00:00:00 2001 From: Yash Johri Date: Tue, 15 Dec 2020 11:26:52 +0530 Subject: [PATCH 1/8] [path_provider_linux] Migrate to null safety --- .../path_provider/path_provider_linux/CHANGELOG.md | 4 ++++ .../path_provider_linux/example/pubspec.yaml | 6 +++--- .../path_provider_linux/example/test/widget_test.dart | 8 ++++---- .../path_provider_linux/lib/path_provider_linux.dart | 8 ++++---- .../path_provider/path_provider_linux/pubspec.yaml | 10 +++++----- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/packages/path_provider/path_provider_linux/CHANGELOG.md b/packages/path_provider/path_provider_linux/CHANGELOG.md index ee382b04710b..2d91234256af 100644 --- a/packages/path_provider/path_provider_linux/CHANGELOG.md +++ b/packages/path_provider/path_provider_linux/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.0-nullsafety + +* Migrate to null safety. + ## 0.1.1+3 * Update Flutter SDK constraint. diff --git a/packages/path_provider/path_provider_linux/example/pubspec.yaml b/packages/path_provider/path_provider_linux/example/pubspec.yaml index 85dbb24bbb29..96ec1477ba49 100644 --- a/packages/path_provider/path_provider_linux/example/pubspec.yaml +++ b/packages/path_provider/path_provider_linux/example/pubspec.yaml @@ -3,17 +3,17 @@ description: Demonstrates how to use the path_provider_linux plugin. publish_to: "none" environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0-0 <3.0.0" dependencies: flutter: sdk: flutter - path_provider: ^1.6.10 + path_provider: ^1.6.24 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.3 + cupertino_icons: ^1.0.1+1 dependency_overrides: path_provider_linux: diff --git a/packages/path_provider/path_provider_linux/example/test/widget_test.dart b/packages/path_provider/path_provider_linux/example/test/widget_test.dart index 8ebda3b77176..086b6d614e13 100644 --- a/packages/path_provider/path_provider_linux/example/test/widget_test.dart +++ b/packages/path_provider/path_provider_linux/example/test/widget_test.dart @@ -30,7 +30,7 @@ void main() { find.byWidgetPredicate( (Widget widget) => widget is Text && - widget.data.startsWith('Temp Directory: /tmp'), + widget.data!.startsWith('Temp Directory: /tmp'), ), findsOneWidget, ); @@ -48,7 +48,7 @@ void main() { find.byWidgetPredicate( (Widget widget) => widget is Text && - widget.data.startsWith('Documents Directory: /'), + widget.data!.startsWith('Documents Directory: /'), ), findsOneWidget, ); @@ -66,7 +66,7 @@ void main() { find.byWidgetPredicate( (Widget widget) => widget is Text && - widget.data.startsWith('Downloads Directory: /'), + widget.data!.startsWith('Downloads Directory: /'), ), findsOneWidget, ); @@ -85,7 +85,7 @@ void main() { find.byWidgetPredicate( (Widget widget) => widget is Text && - widget.data.startsWith('Application Support Directory: /'), + widget.data!.startsWith('Application Support Directory: /'), ), findsOneWidget, ); diff --git a/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart b/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart index 09d2447c0a6c..5667e07adf8e 100644 --- a/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart +++ b/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart @@ -18,12 +18,12 @@ class PathProviderLinux extends PathProviderPlatform { } @override - Future getTemporaryPath() { + Future getTemporaryPath() { return Future.value("/tmp"); } @override - Future getApplicationSupportPath() async { + Future getApplicationSupportPath() async { final processName = path.basenameWithoutExtension( await File('/proc/self/exe').resolveSymbolicLinks()); final directory = Directory(path.join(xdg.dataHome.path, processName)); @@ -35,12 +35,12 @@ class PathProviderLinux extends PathProviderPlatform { } @override - Future getApplicationDocumentsPath() { + Future getApplicationDocumentsPath() { return Future.value(xdg.getUserDirectory('DOCUMENTS').path); } @override - Future getDownloadsPath() { + Future getDownloadsPath() { return Future.value(xdg.getUserDirectory('DOWNLOAD').path); } } diff --git a/packages/path_provider/path_provider_linux/pubspec.yaml b/packages/path_provider/path_provider_linux/pubspec.yaml index adabbdd45246..968b61882ab3 100644 --- a/packages/path_provider/path_provider_linux/pubspec.yaml +++ b/packages/path_provider/path_provider_linux/pubspec.yaml @@ -1,6 +1,6 @@ name: path_provider_linux description: linux implementation of the path_provider plugin -version: 0.1.1+3 +version: 1.0.0-nullsafety homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_linux flutter: @@ -11,17 +11,17 @@ flutter: pluginClass: none environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0-0 <3.0.0" flutter: ">=1.10.0" dependencies: - path: ^1.6.4 + path: ^1.8.0-nullsafety.3 xdg_directories: ^0.1.0 - path_provider_platform_interface: ^1.0.1 + path_provider_platform_interface: ^2.0.0-nullsafety flutter: sdk: flutter dev_dependencies: flutter_test: sdk: flutter - pedantic: ^1.8.0 + pedantic: ^1.10.0-nullsafety.1 From 3cb7d3f2ef0bbc3aaf15a96d0c5043071860df19 Mon Sep 17 00:00:00 2001 From: Yash Johri Date: Fri, 29 Jan 2021 22:29:06 +0530 Subject: [PATCH 2/8] Updating dependencies --- packages/path_provider/path_provider_linux/pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/path_provider/path_provider_linux/pubspec.yaml b/packages/path_provider/path_provider_linux/pubspec.yaml index 968b61882ab3..d8c01b3e8cc7 100644 --- a/packages/path_provider/path_provider_linux/pubspec.yaml +++ b/packages/path_provider/path_provider_linux/pubspec.yaml @@ -16,7 +16,7 @@ environment: dependencies: path: ^1.8.0-nullsafety.3 - xdg_directories: ^0.1.0 + xdg_directories: ^0.2.0-nullsafety.0 path_provider_platform_interface: ^2.0.0-nullsafety flutter: sdk: flutter @@ -24,4 +24,4 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - pedantic: ^1.10.0-nullsafety.1 + pedantic: ^1.10.0-nullsafety.3 From e2dfbba68f46b439100f30bcd0664c2ff90bb70c Mon Sep 17 00:00:00 2001 From: Yash Johri Date: Fri, 29 Jan 2021 22:30:05 +0530 Subject: [PATCH 3/8] Null checks --- .../path_provider_linux/lib/path_provider_linux.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart b/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart index 5667e07adf8e..e35b73bf3766 100644 --- a/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart +++ b/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart @@ -36,11 +36,11 @@ class PathProviderLinux extends PathProviderPlatform { @override Future getApplicationDocumentsPath() { - return Future.value(xdg.getUserDirectory('DOCUMENTS').path); + return Future.value(xdg.getUserDirectory('DOCUMENTS')?.path); } @override Future getDownloadsPath() { - return Future.value(xdg.getUserDirectory('DOWNLOAD').path); + return Future.value(xdg.getUserDirectory('DOWNLOAD')?.path); } } From b4af63a4c128b6e0cf980dba63e918499376f2d3 Mon Sep 17 00:00:00 2001 From: Yash Johri Date: Tue, 2 Feb 2021 10:19:42 +0530 Subject: [PATCH 4/8] Update version --- packages/path_provider/path_provider_linux/CHANGELOG.md | 2 +- packages/path_provider/path_provider_linux/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/path_provider/path_provider_linux/CHANGELOG.md b/packages/path_provider/path_provider_linux/CHANGELOG.md index 2d91234256af..2deb84237712 100644 --- a/packages/path_provider/path_provider_linux/CHANGELOG.md +++ b/packages/path_provider/path_provider_linux/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.0.0-nullsafety +## 0.2.0-nullsafety * Migrate to null safety. diff --git a/packages/path_provider/path_provider_linux/pubspec.yaml b/packages/path_provider/path_provider_linux/pubspec.yaml index d8c01b3e8cc7..846ef4df86b1 100644 --- a/packages/path_provider/path_provider_linux/pubspec.yaml +++ b/packages/path_provider/path_provider_linux/pubspec.yaml @@ -1,6 +1,6 @@ name: path_provider_linux description: linux implementation of the path_provider plugin -version: 1.0.0-nullsafety +version: 0.2.0-nullsafety homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_linux flutter: From 0b3b433c15ccb7dc4a9f68fe32fcb4fbae9d4991 Mon Sep 17 00:00:00 2001 From: Yash Johri Date: Wed, 3 Feb 2021 17:18:21 +0530 Subject: [PATCH 5/8] Fixes overrides --- .../path_provider/path_provider_linux/example/pubspec.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/path_provider/path_provider_linux/example/pubspec.yaml b/packages/path_provider/path_provider_linux/example/pubspec.yaml index 96ec1477ba49..3f601e6c464b 100644 --- a/packages/path_provider/path_provider_linux/example/pubspec.yaml +++ b/packages/path_provider/path_provider_linux/example/pubspec.yaml @@ -9,15 +9,16 @@ dependencies: flutter: sdk: flutter - path_provider: ^1.6.24 + path_provider: ^1.6.27 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.1+1 + cupertino_icons: ^1.0.2 dependency_overrides: path_provider_linux: path: ../ + path_provider_platform_interface: ^2.0.0-nullsafety dev_dependencies: flutter_test: From e3213f93f0f0adc6460404061d7228c8d6b7dfaf Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 3 Feb 2021 11:20:30 -0500 Subject: [PATCH 6/8] Update example to use path_provider_windows, and revert its NNBD changes --- .../integration_test/path_provider_test.dart | 21 ++++++++++++------- .../path_provider_linux/example/lib/main.dart | 11 +++++----- .../flutter/generated_plugin_registrant.cc | 4 +++- .../path_provider_linux/example/pubspec.yaml | 7 +++---- .../example/test/widget_test.dart | 8 +++---- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/packages/path_provider/path_provider_linux/example/integration_test/path_provider_test.dart b/packages/path_provider/path_provider_linux/example/integration_test/path_provider_test.dart index 18ac49debbd4..febd52172759 100644 --- a/packages/path_provider/path_provider_linux/example/integration_test/path_provider_test.dart +++ b/packages/path_provider/path_provider_linux/example/integration_test/path_provider_test.dart @@ -4,14 +4,15 @@ import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; -import 'package:path_provider/path_provider.dart'; +import 'package:path_provider_linux/path_provider_linux.dart'; import 'package:integration_test/integration_test.dart'; void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); testWidgets('getTemporaryDirectory', (WidgetTester tester) async { - final Directory result = await getTemporaryDirectory(); + final PathProviderLinux provider = PathProviderLinux(); + final String result = await provider.getTemporaryPath(); _verifySampleFile(result, 'temporaryDirectory'); }); @@ -19,25 +20,29 @@ void main() { if (!Platform.isLinux) { return; } - final Directory result = await getDownloadsDirectory(); + final PathProviderLinux provider = PathProviderLinux(); + final String result = await provider.getDownloadsPath(); _verifySampleFile(result, 'downloadDirectory'); }); testWidgets('getApplicationDocumentsDirectory', (WidgetTester tester) async { - final Directory result = await getApplicationDocumentsDirectory(); + final PathProviderLinux provider = PathProviderLinux(); + final String result = await provider.getApplicationDocumentsPath(); _verifySampleFile(result, 'applicationDocuments'); }); testWidgets('getApplicationSupportDirectory', (WidgetTester tester) async { - final Directory result = await getApplicationSupportDirectory(); + final PathProviderLinux provider = PathProviderLinux(); + final String result = await provider.getApplicationSupportPath(); _verifySampleFile(result, 'applicationSupport'); }); } -/// Verify a file called [name] in [directory] by recreating it with test +/// Verify a file called [name] in [directoryPath] by recreating it with test /// contents when necessary. -void _verifySampleFile(Directory directory, String name) { - final File file = File('${directory.path}/$name'); +void _verifySampleFile(String directoryPath, String name) { + final Directory directory = Directory(directoryPath); + final File file = File('${directory.path}${Platform.pathSeparator}$name'); if (file.existsSync()) { file.deleteSync(); diff --git a/packages/path_provider/path_provider_linux/example/lib/main.dart b/packages/path_provider/path_provider_linux/example/lib/main.dart index 6dc364b77f2a..069308233acb 100644 --- a/packages/path_provider/path_provider_linux/example/lib/main.dart +++ b/packages/path_provider/path_provider_linux/example/lib/main.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'dart:async'; import 'package:flutter/services.dart'; -import 'package:path_provider/path_provider.dart'; +import 'package:path_provider_linux/path_provider_linux.dart'; void main() async { runApp(MyApp()); @@ -19,6 +19,7 @@ class _MyAppState extends State { String _downloadsDirectory = 'Unknown'; String _appSupportDirectory = 'Unknown'; String _documentsDirectory = 'Unknown'; + final PathProviderLinux _provider = PathProviderLinux(); @override void initState() { @@ -34,27 +35,27 @@ class _MyAppState extends State { String documentsDirectory; // Platform messages may fail, so we use a try/catch PlatformException. try { - tempDirectory = (await getTemporaryDirectory()).path; + tempDirectory = await _provider.getTemporaryPath(); } on PlatformException catch (e, stackTrace) { tempDirectory = 'Failed to get temp directory.'; print('$tempDirectory $e $stackTrace'); } try { - downloadsDirectory = (await getDownloadsDirectory()).path; + downloadsDirectory = await _provider.getDownloadsPath(); } on PlatformException catch (e, stackTrace) { downloadsDirectory = 'Failed to get downloads directory.'; print('$downloadsDirectory $e $stackTrace'); } try { - documentsDirectory = (await getApplicationDocumentsDirectory()).path; + documentsDirectory = await _provider.getApplicationDocumentsPath(); } on PlatformException catch (e, stackTrace) { documentsDirectory = 'Failed to get documents directory.'; print('$documentsDirectory $e $stackTrace'); } try { - appSupportDirectory = (await getApplicationSupportDirectory()).path; + appSupportDirectory = await _provider.getApplicationSupportPath(); } on PlatformException catch (e, stackTrace) { appSupportDirectory = 'Failed to get documents directory.'; print('$appSupportDirectory $e $stackTrace'); diff --git a/packages/path_provider/path_provider_linux/example/linux/flutter/generated_plugin_registrant.cc b/packages/path_provider/path_provider_linux/example/linux/flutter/generated_plugin_registrant.cc index 890de29bbab1..d38195aa0412 100644 --- a/packages/path_provider/path_provider_linux/example/linux/flutter/generated_plugin_registrant.cc +++ b/packages/path_provider/path_provider_linux/example/linux/flutter/generated_plugin_registrant.cc @@ -4,4 +4,6 @@ #include "generated_plugin_registrant.h" -void fl_register_plugins(FlPluginRegistry* registry) {} + +void fl_register_plugins(FlPluginRegistry* registry) { +} diff --git a/packages/path_provider/path_provider_linux/example/pubspec.yaml b/packages/path_provider/path_provider_linux/example/pubspec.yaml index 3f601e6c464b..d66af910c998 100644 --- a/packages/path_provider/path_provider_linux/example/pubspec.yaml +++ b/packages/path_provider/path_provider_linux/example/pubspec.yaml @@ -3,22 +3,21 @@ description: Demonstrates how to use the path_provider_linux plugin. publish_to: "none" environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.1.0 <3.0.0" dependencies: flutter: sdk: flutter - path_provider: ^1.6.27 + path_provider_linux: any # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.2 + cupertino_icons: ^0.1.3 dependency_overrides: path_provider_linux: path: ../ - path_provider_platform_interface: ^2.0.0-nullsafety dev_dependencies: flutter_test: diff --git a/packages/path_provider/path_provider_linux/example/test/widget_test.dart b/packages/path_provider/path_provider_linux/example/test/widget_test.dart index 086b6d614e13..8ebda3b77176 100644 --- a/packages/path_provider/path_provider_linux/example/test/widget_test.dart +++ b/packages/path_provider/path_provider_linux/example/test/widget_test.dart @@ -30,7 +30,7 @@ void main() { find.byWidgetPredicate( (Widget widget) => widget is Text && - widget.data!.startsWith('Temp Directory: /tmp'), + widget.data.startsWith('Temp Directory: /tmp'), ), findsOneWidget, ); @@ -48,7 +48,7 @@ void main() { find.byWidgetPredicate( (Widget widget) => widget is Text && - widget.data!.startsWith('Documents Directory: /'), + widget.data.startsWith('Documents Directory: /'), ), findsOneWidget, ); @@ -66,7 +66,7 @@ void main() { find.byWidgetPredicate( (Widget widget) => widget is Text && - widget.data!.startsWith('Downloads Directory: /'), + widget.data.startsWith('Downloads Directory: /'), ), findsOneWidget, ); @@ -85,7 +85,7 @@ void main() { find.byWidgetPredicate( (Widget widget) => widget is Text && - widget.data!.startsWith('Application Support Directory: /'), + widget.data.startsWith('Application Support Directory: /'), ), findsOneWidget, ); From dfe98431617ba24a4efb357a70c717d864f0e526 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 3 Feb 2021 13:30:07 -0500 Subject: [PATCH 7/8] Get fixed version of xdg_directories --- packages/path_provider/path_provider_linux/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/path_provider/path_provider_linux/pubspec.yaml b/packages/path_provider/path_provider_linux/pubspec.yaml index 846ef4df86b1..df459e12d37f 100644 --- a/packages/path_provider/path_provider_linux/pubspec.yaml +++ b/packages/path_provider/path_provider_linux/pubspec.yaml @@ -16,7 +16,7 @@ environment: dependencies: path: ^1.8.0-nullsafety.3 - xdg_directories: ^0.2.0-nullsafety.0 + xdg_directories: ^0.2.0-nullsafety.1 path_provider_platform_interface: ^2.0.0-nullsafety flutter: sdk: flutter From b2598d93a2b0984c7b237b9c5493277f83b85c86 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 3 Feb 2021 15:17:54 -0500 Subject: [PATCH 8/8] Fix latent code format issue --- .../example/linux/flutter/generated_plugin_registrant.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/path_provider/path_provider_linux/example/linux/flutter/generated_plugin_registrant.cc b/packages/path_provider/path_provider_linux/example/linux/flutter/generated_plugin_registrant.cc index d38195aa0412..890de29bbab1 100644 --- a/packages/path_provider/path_provider_linux/example/linux/flutter/generated_plugin_registrant.cc +++ b/packages/path_provider/path_provider_linux/example/linux/flutter/generated_plugin_registrant.cc @@ -4,6 +4,4 @@ #include "generated_plugin_registrant.h" - -void fl_register_plugins(FlPluginRegistry* registry) { -} +void fl_register_plugins(FlPluginRegistry* registry) {}