8000 [path_provider] linux endorsement by TimWhiting · Pull Request #2789 · flutter/plugins · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[path_provider] linux endorsement #2789

Merged
merged 14 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/path_provider/path_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.6.10
* Linux implementation endorsement

## 1.6.9

* Post-v2 Android embedding cleanups.
Expand Down
37 changes: 35 additions & 2 deletions packages/path_provider/path_provider/lib/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions packages/path_provider/path_provider/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.9
version: 1.6.10

flutter:
plugin:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ 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.
// See this issue https://github.com/flutter/flutter/issues/52267 for details
disablePathProviderPlatformOverride = true;
});

test('getTemporaryDirectory', () async {
Expand Down
3 changes: 3 additions & 0 deletions packages/path_provider/path_provider_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 4 additions & 26 deletions packages/path_provider/path_provider_linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 0 additions & 10 deletions packages/path_provider/path_provider_linux/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@ 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 {
// 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.
Expand All @@ -43,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.
Expand All @@ -61,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.
Expand All @@ -80,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion packages/path_provider/path_provider_linux/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions script/build_all_plugins_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
0