Skip to content

Commit

Permalink
Revert "[path_provider] Add Windows support (flutter#2818)"
Browse files Browse the repository at this point in the history
This reverts commit 1685a28.
  • Loading branch information
nabil6391 committed Sep 18, 2020
1 parent 1685a28 commit cd89d40
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 946 deletions.
5 changes: 0 additions & 5 deletions packages/path_provider/path_provider/CHANGELOG.md
@@ -1,8 +1,3 @@
## 1.6.15

* Endorse Windows implementation.
* Remove the need to call disablePathProviderPlatformOverride in tests

## 1.6.14

* Update package:e2e -> package:integration_test
Expand Down
9 changes: 8 additions & 1 deletion packages/path_provider/path_provider/README.md
Expand Up @@ -23,7 +23,14 @@ Please see the example app of this plugin for a full example.

### Usage in tests

`path_provider` now uses a `PlatformInterface`, meaning that not all platforms share the a single `PlatformChannel`-based implementation.
`path_provider` now uses a `PlatformInterface`, meaning that not all platforms share the a single `PlatformChannel`-based implementation.
With that change, tests should be updated to mock `PathProviderPlatform` rather than `PlatformChannel`.

See this `path_provider` [test](https://github.com/flutter/plugins/blob/master/packages/path_provider/path_provider/test/path_provider_test.dart) for an example.

You will also have to temporarily add the following line to the setup of your test.
```dart
disablePathProviderPlatformOverride = true;
```

See this [issue](https://github.com/flutter/flutter/issues/52267), for more details on why this is needed.
47 changes: 26 additions & 21 deletions packages/path_provider/path_provider/lib/path_provider.dart
Expand Up @@ -7,37 +7,42 @@ 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_windows/path_provider_windows.dart';
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
import 'package:path_provider_platform_interface/src/method_channel_path_provider.dart';

export 'package:path_provider_platform_interface/path_provider_platform_interface.dart'
show StorageDirectory;

/// 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
@Deprecated('This is no longer necessary, and is now a no-op')
set disablePathProviderPlatformOverride(bool override) {}
set disablePathProviderPlatformOverride(bool override) {
_disablePlatformOverride = override;
}

bool _manualDartRegistrationNeeded = true;
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 {
// This is to manually endorse Dart implementations until automatic
// registration of Dart plugins is implemented. For details see
// https://github.com/flutter/flutter/issues/52267.
if (_manualDartRegistrationNeeded) {
// Only do the initial registration if it hasn't already been overridden
// with a non-default instance.
if (!kIsWeb && PathProviderPlatform.instance is MethodChannelPathProvider) {
if (Platform.isLinux) {
PathProviderPlatform.instance = PathProviderLinux();
} else if (Platform.isWindows) {
PathProviderPlatform.instance = PathProviderWindows();
}
}
_manualDartRegistrationNeeded = false;
if (__platform != null) {
return __platform;
}

return PathProviderPlatform.instance;
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
Expand Down
8 changes: 3 additions & 5 deletions packages/path_provider/path_provider/pubspec.yaml
@@ -1,7 +1,8 @@
name: path_provider
description: Flutter plugin for getting commonly used locations on host platform file systems, such as the temp and app data directories.
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.15
version: 1.6.14

flutter:
plugin:
Expand All @@ -15,16 +16,13 @@ flutter:
default_package: path_provider_macos
linux:
default_package: path_provider_linux
windows:
default_package: path_provider_windows

dependencies:
flutter:
sdk: flutter
path_provider_platform_interface: ^1.0.1
path_provider_macos: ^0.0.4
path_provider_linux: ^0.0.1
path_provider_windows: ^0.0.1

dev_dependencies:
integration_test:
Expand Down
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: 0 additions & 3 deletions packages/path_provider/path_provider_windows/.gitignore

This file was deleted.

11 changes: 0 additions & 11 deletions packages/path_provider/path_provider_windows/CHANGELOG.md

This file was deleted.

25 changes: 0 additions & 25 deletions packages/path_provider/path_provider_windows/LICENSE

This file was deleted.

31 changes: 0 additions & 31 deletions packages/path_provider/path_provider_windows/README.md

This file was deleted.

44 changes: 0 additions & 44 deletions packages/path_provider/path_provider_windows/example/.gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions packages/path_provider/path_provider_windows/example/.metadata

This file was deleted.

This file was deleted.

93 changes: 0 additions & 93 deletions packages/path_provider/path_provider_windows/example/lib/main.dart

This file was deleted.

21 changes: 0 additions & 21 deletions packages/path_provider/path_provider_windows/example/pubspec.yaml

This file was deleted.

0 comments on commit cd89d40

Please sign in to comment.