From 1752cd6719e98234beb5c1eed3c746cdacb480ce Mon Sep 17 00:00:00 2001 From: Tim Whiting Date: Thu, 21 May 2020 13:09:13 -0600 Subject: [PATCH 01/11] path provider linux endorsement --- packages/path_provider/path_provider/CHANGELOG.md | 4 ++++ .../path_provider/path_provider/lib/path_provider.dart | 8 ++++++-- packages/path_provider/path_provider/pubspec.yaml | 6 ++++-- .../path_provider_linux/example/lib/main.dart | 10 ---------- .../path_provider_linux/example/pubspec.yaml | 7 ++----- .../path_provider_linux/example/test/widget_test.dart | 3 --- .../example/test_driver/path_provider_e2e.dart | 6 +----- 7 files changed, 17 insertions(+), 27 deletions(-) diff --git a/packages/path_provider/path_provider/CHANGELOG.md b/packages/path_provider/path_provider/CHANGELOG.md index 4a94b4c046b4..530e42a944c6 100644 --- a/packages/path_provider/path_provider/CHANGELOG.md +++ b/packages/path_provider/path_provider/CHANGELOG.md @@ -1,5 +1,9 @@ ## 1.6.8 +* Endorsed linux implementation. + +## 1.6.8 + * Update lower bound of dart dependency to 2.1.0. ## 1.6.7 diff --git a/packages/path_provider/path_provider/lib/path_provider.dart b/packages/path_provider/path_provider/lib/path_provider.dart index a7643264d52a..74345df6dbd4 100644 --- a/packages/path_provider/path_provider/lib/path_provider.dart +++ b/packages/path_provider/path_provider/lib/path_provider.dart @@ -3,14 +3,18 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:io' show Directory; +import 'dart:io' show Directory, Platform; +import 'package:path_provider_linux/path_provider_linux.dart'; import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; export 'package:path_provider_platform_interface/path_provider_platform_interface.dart' show StorageDirectory; -PathProviderPlatform get _platform => PathProviderPlatform.instance; +final PathProviderPlatform _linuxPathProvider = + Platform.isLinux ? PathProviderLinux() : null; +PathProviderPlatform get _platform => + _linuxPathProvider ?? PathProviderPlatform.instance; /// Path to the temporary directory on the device that is not backed up and is /// suitable for storing caches of downloaded files. diff --git a/packages/path_provider/path_provider/pubspec.yaml b/packages/path_provider/path_provider/pubspec.yaml index 28ac7744ed9c..0ea47f1850a7 100644 --- a/packages/path_provider/path_provider/pubspec.yaml +++ b/packages/path_provider/path_provider/pubspec.yaml @@ -2,7 +2,7 @@ name: path_provider description: Flutter plugin for getting commonly used locations on the Android & iOS file systems, such as the temp and app data directories. homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider -version: 1.6.8 +version: 1.6.9 flutter: plugin: @@ -14,13 +14,15 @@ flutter: pluginClass: FLTPathProviderPlugin macos: default_package: path_provider_macos - + linux: + default_package: path_provider_linux dependencies: flutter: sdk: flutter path_provider_platform_interface: ^1.0.1 path_provider_macos: ^0.0.4 + path_provider_linux: ^0.0.1 dev_dependencies: e2e: ^0.2.1 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 b01afb7c86e3..edba63482ad5 100644 --- a/packages/path_provider/path_provider_linux/example/lib/main.dart +++ b/packages/path_provider/path_provider_linux/example/lib/main.dart @@ -1,20 +1,10 @@ -import 'dart:io'; - import 'package:flutter/material.dart'; import 'dart:async'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; -// TODO: Remove the following two lines once path provider endorses the linux plugin -import 'package:path_provider_linux/path_provider_linux.dart'; -import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; void main() async { - // TODO: Remove the following four lines once path provider endorses the linux plugin - if (Platform.isLinux) { - await WidgetsFlutterBinding.ensureInitialized(); - PathProviderPlatform.instance = PathProviderLinux(); - } runApp(MyApp()); } diff --git a/packages/path_provider/path_provider_linux/example/pubspec.yaml b/packages/path_provider/path_provider_linux/example/pubspec.yaml index 2cfe89caefbc..0b9b74792f1f 100644 --- a/packages/path_provider/path_provider_linux/example/pubspec.yaml +++ b/packages/path_provider/path_provider_linux/example/pubspec.yaml @@ -9,11 +9,8 @@ dependencies: flutter: sdk: flutter - path_provider: any - - # TODO: Remove this once path provider endorses the linux implementation - path_provider_linux: - path: ../ + path_provider: + path: ../../path_provider # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. 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 99be40a7427a..6a18c7d71a8d 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 @@ -9,16 +9,13 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:path_provider_linux/path_provider_linux.dart'; import 'package:pathproviderexample/main.dart'; -import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; void main() { group('Test linux path provider example', () { setUpAll(() async { await WidgetsFlutterBinding.ensureInitialized(); - PathProviderPlatform.instance = PathProviderLinux(); }); testWidgets('Finds tmp directory', (WidgetTester tester) async { diff --git a/packages/path_provider/path_provider_linux/example/test_driver/path_provider_e2e.dart b/packages/path_provider/path_provider_linux/example/test_driver/path_provider_e2e.dart index 5dd6c0dc51a1..c90c4d96dde5 100644 --- a/packages/path_provider/path_provider_linux/example/test_driver/path_provider_e2e.dart +++ b/packages/path_provider/path_provider_linux/example/test_driver/path_provider_e2e.dart @@ -5,15 +5,11 @@ import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; import 'package:path_provider/path_provider.dart'; -import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; -import 'package:path_provider_linux/path_provider_linux.dart'; import 'package:e2e/e2e.dart'; void main() { E2EWidgetsFlutterBinding.ensureInitialized(); - if (Platform.isLinux) { - PathProviderPlatform.instance = PathProviderLinux(); - } + testWidgets('getTemporaryDirectory', (WidgetTester tester) async { final Directory result = await getTemporaryDirectory(); _verifySampleFile(result, 'temporaryDirectory'); From 31a3092ea9ff2673fb12f745d5c91310f483d0f8 Mon Sep 17 00:00:00 2001 From: Tim Whiting Date: Thu, 21 May 2020 13:18:39 -0600 Subject: [PATCH 02/11] update documentation --- packages/path_provider/path_provider/lib/path_provider.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/path_provider/path_provider/lib/path_provider.dart b/packages/path_provider/path_provider/lib/path_provider.dart index 74345df6dbd4..a39d20eed1a3 100644 --- a/packages/path_provider/path_provider/lib/path_provider.dart +++ b/packages/path_provider/path_provider/lib/path_provider.dart @@ -11,6 +11,7 @@ import 'package:path_provider_platform_interface/path_provider_platform_interfac export 'package:path_provider_platform_interface/path_provider_platform_interface.dart' show StorageDirectory; +// This is to manually endorse the linux path provider until automatic registration of dart plugins is implemented final PathProviderPlatform _linuxPathProvider = Platform.isLinux ? PathProviderLinux() : null; PathProviderPlatform get _platform => From e3f3bb70b48659f89125eb3583c61f3370c2d415 Mon Sep 17 00:00:00 2001 From: Tim Whiting Date: Thu, 21 May 2020 13:24:31 -0600 Subject: [PATCH 03/11] update changelog --- packages/path_provider/path_provider/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/path_provider/path_provider/CHANGELOG.md b/packages/path_provider/path_provider/CHANGELOG.md index 530e42a944c6..878c894d4f2f 100644 --- a/packages/path_provider/path_provider/CHANGELOG.md +++ b/packages/path_provider/path_provider/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.6.8 +## 1.6.9 * Endorsed linux implementation. From f684067b69ba20da44c879f8edbb01a8ae17f4be Mon Sep 17 00:00:00 2001 From: Tim Whiting Date: Thu, 21 May 2020 13:51:39 -0600 Subject: [PATCH 04/11] update the path_provider test --- .../path_provider/lib/path_provider.dart | 11 ++++++++--- .../path_provider/test/path_provider_test.dart | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/path_provider/path_provider/lib/path_provider.dart b/packages/path_provider/path_provider/lib/path_provider.dart index a39d20eed1a3..e1eec26526f2 100644 --- a/packages/path_provider/path_provider/lib/path_provider.dart +++ b/packages/path_provider/path_provider/lib/path_provider.dart @@ -5,17 +5,22 @@ import 'dart:async'; import 'dart:io' show Directory, Platform; +import 'package:flutter/foundation.dart' show visibleForTesting; import 'package:path_provider_linux/path_provider_linux.dart'; import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; export 'package:path_provider_platform_interface/path_provider_platform_interface.dart' show StorageDirectory; -// This is to manually endorse the linux path provider until automatic registration of dart plugins is implemented -final PathProviderPlatform _linuxPathProvider = +/// This is the Linux path provider instance when the target platform is Linux. +/// +/// This is to manually endorse the linux path provider until automatic registration of dart plugins is implemented. +/// Should not be used in users' code, just made visible for testing +@visibleForTesting +PathProviderPlatform linuxPathProvider = Platform.isLinux ? PathProviderLinux() : null; PathProviderPlatform get _platform => - _linuxPathProvider ?? PathProviderPlatform.instance; + linuxPathProvider ?? PathProviderPlatform.instance; /// Path to the temporary directory on the device that is not backed up and is /// suitable for storing caches of downloaded files. diff --git a/packages/path_provider/path_provider/test/path_provider_test.dart b/packages/path_provider/path_provider/test/path_provider_test.dart index eb17178b9975..872c82e86bae 100644 --- a/packages/path_provider/path_provider/test/path_provider_test.dart +++ b/packages/path_provider/path_provider/test/path_provider_test.dart @@ -25,6 +25,9 @@ void main() { setUp(() async { PathProviderPlatform.instance = MockPathProviderPlatform(); + // This is required because we manually register the Linux path provider when on the Linux platform. + // Will be removed when automatic registration of dart plugins is implemented. + linuxPathProvider = null; }); test('getTemporaryDirectory', () async { From 5a5a8ad1d9e7b86c9951a1da0f24f69b0a93ee40 Mon Sep 17 00:00:00 2001 From: Tim Whiting Date: Thu, 21 May 2020 14:22:20 -0600 Subject: [PATCH 05/11] fix all_plugins build failure --- script/build_all_plugins_app.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script/build_all_plugins_app.sh b/script/build_all_plugins_app.sh index 0d670af88814..2c0a90693851 100755 --- a/script/build_all_plugins_app.sh +++ b/script/build_all_plugins_app.sh @@ -21,6 +21,7 @@ readonly EXCLUDED_PLUGINS_LIST=( "google_sign_in_web" "image_picker_platform_interface" "instrumentation_adapter" + "path_provider_linux" "path_provider_macos" "path_provider_platform_interface" "path_provider_web" From b4c61a73b08598cc8dab21eb79e5e068aecbaa9f Mon Sep 17 00:00:00 2001 From: Tim Whiting Date: Fri, 22 May 2020 08:44:04 -0600 Subject: [PATCH 06/11] cleaned up the implementation slightly to be more readable and reflect the suggestions for manual registrations in the design document, also bumped the linux path provider version since updated readme and example to reflect the endorsement --- .../path_provider/lib/path_provider.dart | 26 +++++++++++++------ .../test/path_provider_test.dart | 2 +- .../path_provider_linux/CHANGELOG.md | 3 +++ .../path_provider_linux/README.md | 17 ++++-------- .../path_provider_linux/pubspec.yaml | 2 +- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/packages/path_provider/path_provider/lib/path_provider.dart b/packages/path_provider/path_provider/lib/path_provider.dart index e1eec26526f2..8eddc2015457 100644 --- a/packages/path_provider/path_provider/lib/path_provider.dart +++ b/packages/path_provider/path_provider/lib/path_provider.dart @@ -12,15 +12,25 @@ import 'package:path_provider_platform_interface/path_provider_platform_interfac export 'package:path_provider_platform_interface/path_provider_platform_interface.dart' show StorageDirectory; -/// This is the Linux path provider instance when the target platform is Linux. -/// -/// This is to manually endorse the linux path provider until automatic registration of dart plugins is implemented. -/// Should not be used in users' code, just made visible for testing +// Should not be used in users' code, just made visible for testing to test the method channel implementation @visibleForTesting -PathProviderPlatform linuxPathProvider = - Platform.isLinux ? PathProviderLinux() : null; -PathProviderPlatform get _platform => - linuxPathProvider ?? PathProviderPlatform.instance; +set testOverrideUseMethodChannel(bool override) { + _useMethodChannel = override; +} + +bool _useMethodChannel = false; +PathProviderPlatform __platform; + +// This is to manually endorse the linux path provider until automatic registration of dart plugins is implemented. +PathProviderPlatform get _platform { + if (__platform != null) { + return __platform; + } + if (Platform.isLinux && !_useMethodChannel) { + __platform = PathProviderLinux(); + } + return __platform = PathProviderPlatform.instance; +} /// Path to the temporary directory on the device that is not backed up and is /// suitable for storing caches of downloaded files. diff --git a/packages/path_provider/path_provider/test/path_provider_test.dart b/packages/path_provider/path_provider/test/path_provider_test.dart index 872c82e86bae..ba8556aa675c 100644 --- a/packages/path_provider/path_provider/test/path_provider_test.dart +++ b/packages/path_provider/path_provider/test/path_provider_test.dart @@ -27,7 +27,7 @@ void main() { PathProviderPlatform.instance = MockPathProviderPlatform(); // This is required because we manually register the Linux path provider when on the Linux platform. // Will be removed when automatic registration of dart plugins is implemented. - linuxPathProvider = null; + testOverrideUseMethodChannel = true; }); test('getTemporaryDirectory', () async { diff --git a/packages/path_provider/path_provider_linux/CHANGELOG.md b/packages/path_provider/path_provider_linux/CHANGELOG.md index 5592340216dc..8c9cf2f97f8f 100644 --- a/packages/path_provider/path_provider_linux/CHANGELOG.md +++ b/packages/path_provider/path_provider_linux/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.0.1+1 +* This updates the readme and pubspec and example to reflect the endorsement of this implementation of `path_provider` + ## 0.0.1 * The initial implementation of path_provider for Linux diff --git a/packages/path_provider/path_provider_linux/README.md b/packages/path_provider/path_provider_linux/README.md index 70097d730559..25d23c955719 100644 --- a/packages/path_provider/path_provider_linux/README.md +++ b/packages/path_provider/path_provider_linux/README.md @@ -2,23 +2,18 @@ The linux implementation of [`path_provider`]. -**Please set your constraint to `path_provider_linux: '>=0.0.y+x <2.0.0'`** +**Please set your constraint to `path_provider: '>=0.0.y+x <2.0.0'`** ## Backward compatible 1.0.0 version is coming The `path_provider` plugin has reached a stable API, we guarantee that version `1.0.0` will be backward compatible with `0.0.y+z`. -Please use `path_provider_linux: '>=0.0.y+x <2.0.0'` as your dependency constraint to allow a smoother ecosystem migration. +Please use `path_provider: '>=0.0.y+x <2.0.0'` as your dependency constraint to allow a smoother ecosystem migration. For more details see: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0 ## Usage ### Import the package -To use this plugin in your Flutter linux app, simply add it as a dependency in -your `pubspec.yaml` alongside the base `path_provider` plugin. - -_(This is only temporary: in the future we hope to make this package an -"endorsed" implementation of `path_provider`, so that it is automatically -included in your Flutter linux app when you depend on `package:path_provider`.)_ +This package is already included as part of the `path_provider` package dependency. So just include it. This is what the above means to your `pubspec.yaml`: @@ -26,12 +21,10 @@ This is what the above means to your `pubspec.yaml`: ... dependencies: ... - path_provider: ^1.5.1 - path_provider_linux: ^0.0.1 + path_provider: ^1.6.9 ... ``` ### Use the plugin -Once you have the `path_provider_linux` dependency in your pubspec, you should -be able to use `package:path_provider` as normal. +You should be able to use `package:path_provider` as normal. diff --git a/packages/path_provider/path_provider_linux/pubspec.yaml b/packages/path_provider/path_provider_linux/pubspec.yaml index 77bfba260d82..a3277904bb6e 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.0.1 +version: 0.0.1+1 homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_linux flutter: From 0cd2b1f5a01286582730003829307defa8afea11 Mon Sep 17 00:00:00 2001 From: Tim Whiting Date: Fri, 22 May 2020 08:53:58 -0600 Subject: [PATCH 07/11] fixed return statement --- packages/path_provider/path_provider/lib/path_provider.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/path_provider/path_provider/lib/path_provider.dart b/packages/path_provider/path_provider/lib/path_provider.dart index 8eddc2015457..f5dc958be191 100644 --- a/packages/path_provider/path_provider/lib/path_provider.dart +++ b/packages/path_provider/path_provider/lib/path_provider.dart @@ -28,8 +28,10 @@ PathProviderPlatform get _platform { } if (Platform.isLinux && !_useMethodChannel) { __platform = PathProviderLinux(); + } else { + __platform = PathProviderPlatform.instance; } - return __platform = PathProviderPlatform.instance; + return __platform; } /// Path to the temporary directory on the device that is not backed up and is From 89243863e5dc0dc4ddba4634f1479055ac17eb18 Mon Sep 17 00:00:00 2001 From: Tim Whiting Date: Fri, 22 May 2020 09:10:48 -0600 Subject: [PATCH 08/11] increase timeout for flakey test --- .../path_provider_linux/example/test/widget_test.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 6a18c7d71a8d..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 @@ -22,7 +22,7 @@ void main() { // Build our app and trigger a frame. await tester.runAsync(() async { await tester.pumpWidget(MyApp()); - await Future.delayed(Duration(milliseconds: 10)); + await Future.delayed(Duration(milliseconds: 20)); await tester.pump(); // Verify that temporary directory is retrieved. @@ -40,7 +40,7 @@ void main() { // Build our app and trigger a frame. await tester.runAsync(() async { await tester.pumpWidget(MyApp()); - await Future.delayed(Duration(milliseconds: 10)); + await Future.delayed(Duration(milliseconds: 20)); await tester.pump(); // Verify that documents directory is retrieved. @@ -58,7 +58,7 @@ void main() { // Build our app and trigger a frame. await tester.runAsync(() async { await tester.pumpWidget(MyApp()); - await Future.delayed(Duration(milliseconds: 10)); + await Future.delayed(Duration(milliseconds: 20)); await tester.pump(); // Verify that downloads directory is retrieved. @@ -77,7 +77,7 @@ void main() { // Build our app and trigger a frame. await tester.runAsync(() async { await tester.pumpWidget(MyApp()); - await Future.delayed(Duration(milliseconds: 10)); + await Future.delayed(Duration(milliseconds: 20)); await tester.pump(); // Verify that Application Support Directory is retrieved. From d15c83b3b37214bdacbc5b476ca6cb72b5fa577b Mon Sep 17 00:00:00 2001 From: Tim Whiting Date: Tue, 26 May 2020 13:45:49 -0600 Subject: [PATCH 09/11] addressed all issues except the hidden platform, waiting for response on that --- .../path_provider/lib/path_provider.dart | 5 +++-- .../test/path_provider_test.dart | 1 + .../path_provider_linux/README.md | 19 ++----------------- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/packages/path_provider/path_provider/lib/path_provider.dart b/packages/path_provider/path_provider/lib/path_provider.dart index f5dc958be191..56f0dc14c003 100644 --- a/packages/path_provider/path_provider/lib/path_provider.dart +++ b/packages/path_provider/path_provider/lib/path_provider.dart @@ -5,7 +5,7 @@ import 'dart:async'; import 'dart:io' show Directory, Platform; -import 'package:flutter/foundation.dart' show visibleForTesting; +import 'package:flutter/foundation.dart' show kIsWeb, visibleForTesting; import 'package:path_provider_linux/path_provider_linux.dart'; import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; @@ -22,11 +22,12 @@ bool _useMethodChannel = false; PathProviderPlatform __platform; // This is to manually endorse the linux path provider until automatic registration of dart plugins is implemented. +// See this issue https://github.com/flutter/flutter/issues/52267 for details PathProviderPlatform get _platform { if (__platform != null) { return __platform; } - if (Platform.isLinux && !_useMethodChannel) { + if (!kIsWeb && Platform.isLinux && !_useMethodChannel) { __platform = PathProviderLinux(); } else { __platform = PathProviderPlatform.instance; diff --git a/packages/path_provider/path_provider/test/path_provider_test.dart b/packages/path_provider/path_provider/test/path_provider_test.dart index ba8556aa675c..d8a9ed673d38 100644 --- a/packages/path_provider/path_provider/test/path_provider_test.dart +++ b/packages/path_provider/path_provider/test/path_provider_test.dart @@ -27,6 +27,7 @@ void main() { PathProviderPlatform.instance = MockPathProviderPlatform(); // This is required because we manually register the Linux path provider when on the Linux platform. // Will be removed when automatic registration of dart plugins is implemented. + // See this issue https://github.com/flutter/flutter/issues/52267 for details testOverrideUseMethodChannel = true; }); diff --git a/packages/path_provider/path_provider_linux/README.md b/packages/path_provider/path_provider_linux/README.md index 25d23c955719..373925d2d96d 100644 --- a/packages/path_provider/path_provider_linux/README.md +++ b/packages/path_provider/path_provider_linux/README.md @@ -11,20 +11,5 @@ For more details see: https://github.com/flutter/flutter/wiki/Package-migration- ## Usage -### Import the package - -This package is already included as part of the `path_provider` package dependency. So just include it. - -This is what the above means to your `pubspec.yaml`: - -```yaml -... -dependencies: - ... - path_provider: ^1.6.9 - ... -``` - -### Use the plugin - -You should be able to use `package:path_provider` as normal. +This package is already included as part of the `path_provider` package dependency, and will +be included when using `path_provider` as normal. You will need to use version 1.6.10 or newer. From ce611cdd1f88b1fb44f78b0a6e09b6a4f61d6b87 Mon Sep 17 00:00:00 2001 From: Tim Whiting Date: Wed, 27 May 2020 09:06:38 -0600 Subject: [PATCH 10/11] update with user visible platform override disable, so they can disable the manually registered Linux plugin if they want to manually register another --- .../path_provider/lib/path_provider.dart | 23 +++++++++++++------ .../test/path_provider_test.dart | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/path_provider/path_provider/lib/path_provider.dart b/packages/path_provider/path_provider/lib/path_provider.dart index 56f0dc14c003..adaf71016b14 100644 --- a/packages/path_provider/path_provider/lib/path_provider.dart +++ b/packages/path_provider/path_provider/lib/path_provider.dart @@ -5,20 +5,29 @@ import 'dart:async'; import 'dart:io' show Directory, Platform; -import 'package:flutter/foundation.dart' show kIsWeb, visibleForTesting; +import 'package:flutter/foundation.dart' show kIsWeb; import 'package:path_provider_linux/path_provider_linux.dart'; import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; export 'package:path_provider_platform_interface/path_provider_platform_interface.dart' show StorageDirectory; -// Should not be used in users' code, just made visible for testing to test the method channel implementation -@visibleForTesting -set testOverrideUseMethodChannel(bool override) { - _useMethodChannel = override; +/// Allows the user to disable platform override in order to use a manually registered [PathProviderPlatform] +/// +/// Make sure to disable the override before using any of the `path_provider` methods +/// To use your own [PathProviderPlatform], make sure to include the following lines +/// ``` +/// PathProviderPlatform.instance = YourPathProviderPlatform(); +/// disablePathProviderPlatformOverride = true; +/// // Use the `path_provider` methods: +/// final dir = await getTemporaryDirectory(); +/// ``` +/// See this issue https://github.com/flutter/flutter/issues/52267 for why this is required +set disablePathProviderPlatformOverride(bool override) { + _disablePlatformOverride = override; } -bool _useMethodChannel = false; +bool _disablePlatformOverride = false; PathProviderPlatform __platform; // This is to manually endorse the linux path provider until automatic registration of dart plugins is implemented. @@ -27,7 +36,7 @@ PathProviderPlatform get _platform { if (__platform != null) { return __platform; } - if (!kIsWeb && Platform.isLinux && !_useMethodChannel) { + if (!kIsWeb && Platform.isLinux && !_disablePlatformOverride) { __platform = PathProviderLinux(); } else { __platform = PathProviderPlatform.instance; diff --git a/packages/path_provider/path_provider/test/path_provider_test.dart b/packages/path_provider/path_provider/test/path_provider_test.dart index d8a9ed673d38..90a996fd68c8 100644 --- a/packages/path_provider/path_provider/test/path_provider_test.dart +++ b/packages/path_provider/path_provider/test/path_provider_test.dart @@ -28,7 +28,7 @@ void main() { // This is required because we manually register the Linux path provider when on the Linux platform. // Will be removed when automatic registration of dart plugins is implemented. // See this issue https://github.com/flutter/flutter/issues/52267 for details - testOverrideUseMethodChannel = true; + disablePathProviderPlatformOverride = true; }); test('getTemporaryDirectory', () async { From 30d3220d67d24d6ef660eb58aa4b76706f15a458 Mon Sep 17 00:00:00 2001 From: Tim Whiting Date: Tue, 2 Jun 2020 10:18:58 -0600 Subject: [PATCH 11/11] make the override just visible for testing --- packages/path_provider/path_provider/lib/path_provider.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/path_provider/path_provider/lib/path_provider.dart b/packages/path_provider/path_provider/lib/path_provider.dart index adaf71016b14..ae959b133094 100644 --- a/packages/path_provider/path_provider/lib/path_provider.dart +++ b/packages/path_provider/path_provider/lib/path_provider.dart @@ -5,14 +5,14 @@ import 'dart:async'; import 'dart:io' show Directory, Platform; -import 'package:flutter/foundation.dart' show kIsWeb; +import 'package:flutter/foundation.dart' show kIsWeb, visibleForTesting; import 'package:path_provider_linux/path_provider_linux.dart'; import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; export 'package:path_provider_platform_interface/path_provider_platform_interface.dart' show StorageDirectory; -/// Allows the user to disable platform override in order to use a manually registered [PathProviderPlatform] +/// Disables platform override in order to use a manually registered [PathProviderPlatform], only for testing right now /// /// Make sure to disable the override before using any of the `path_provider` methods /// To use your own [PathProviderPlatform], make sure to include the following lines @@ -23,6 +23,7 @@ export 'package:path_provider_platform_interface/path_provider_platform_interfac /// final dir = await getTemporaryDirectory(); /// ``` /// See this issue https://github.com/flutter/flutter/issues/52267 for why this is required +@visibleForTesting set disablePathProviderPlatformOverride(bool override) { _disablePlatformOverride = override; }