[path_provider] linux endorsement (#2789)
Endorses path_provider_linux, manually registering its implementation as a workaround for https://github.com/flutter/flutter/issues/52267
diff --git a/packages/path_provider/path_provider/CHANGELOG.md b/packages/path_provider/path_provider/CHANGELOG.md
index b3843f2..a2df046 100644
--- a/packages/path_provider/path_provider/CHANGELOG.md
+++ b/packages/path_provider/path_provider/CHANGELOG.md
@@ -1,3 +1,6 @@
+## 1.6.10
+* Linux implementation endorsement
+
## 1.6.9
* Post-v2 Android embedding cleanups.
diff --git a/packages/path_provider/path_provider/lib/path_provider.dart b/packages/path_provider/path_provider/lib/path_provider.dart
index a764326..ae959b1 100644
--- a/packages/path_provider/path_provider/lib/path_provider.dart
+++ b/packages/path_provider/path_provider/lib/path_provider.dart
@@ -3,14 +3,47 @@
// found in the LICENSE file.
import 'dart:async';
-import 'dart:io' show Directory;
+import 'dart:io' show Directory, Platform;
+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;
-PathProviderPlatform get _platform => PathProviderPlatform.instance;
+/// 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
+/// ```
+/// 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
+@visibleForTesting
+set disablePathProviderPlatformOverride(bool override) {
+ _disablePlatformOverride = override;
+}
+
+bool _disablePlatformOverride = 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 (!kIsWeb && Platform.isLinux && !_disablePlatformOverride) {
+ __platform = PathProviderLinux();
+ } else {
+ __platform = PathProviderPlatform.instance;
+ }
+ return __platform;
+}
/// 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 823b755..98059e1 100644
--- a/packages/path_provider/path_provider/pubspec.yaml
+++ b/packages/path_provider/path_provider/pubspec.yaml
@@ -2,7 +2,7 @@
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.9
+version: 1.6.10
flutter:
plugin:
@@ -14,13 +14,15 @@
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/test/path_provider_test.dart b/packages/path_provider/path_provider/test/path_provider_test.dart
index eb17178..90a996f 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,10 @@
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.
+ // See this issue https://github.com/flutter/flutter/issues/52267 for details
+ disablePathProviderPlatformOverride = 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 5592340..8c9cf2f 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 70097d7..373925d 100644
--- a/packages/path_provider/path_provider_linux/README.md
+++ b/packages/path_provider/path_provider_linux/README.md
@@ -2,36 +2,14 @@
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 is what the above means to your `pubspec.yaml`:
-
-```yaml
-...
-dependencies:
- ...
- path_provider: ^1.5.1
- path_provider_linux: ^0.0.1
- ...
-```
-
-### 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.
+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.
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 b01afb7..edba634 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 2cfe89c..0b9b747 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 @@
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 99be40a..8ebda3b 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,23 +9,20 @@
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 {
// 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.
@@ -43,7 +40,7 @@
// 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.
@@ -61,7 +58,7 @@
// 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.
@@ -80,7 +77,7 @@
// 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.
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 5dd6c0d..c90c4d9 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');
diff --git a/packages/path_provider/path_provider_linux/pubspec.yaml b/packages/path_provider/path_provider_linux/pubspec.yaml
index 77bfba2..a327790 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:
diff --git a/script/build_all_plugins_app.sh b/script/build_all_plugins_app.sh
index 0d670af..2c0a906 100755
--- a/script/build_all_plugins_app.sh
+++ b/script/build_all_plugins_app.sh
@@ -21,6 +21,7 @@
"google_sign_in_web"
"image_picker_platform_interface"
"instrumentation_adapter"
+ "path_provider_linux"
"path_provider_macos"
"path_provider_platform_interface"
"path_provider_web"