Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Add implements value to the pubspec #3577

Closed
wants to merge 21 commits into from
Closed
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
4 changes: 4 additions & 0 deletions packages/connectivity/connectivity_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.1

* Add `implements` to pubspec.yaml.

## 0.2.0

* Remove placeholder Dart file.
Expand Down
3 changes: 2 additions & 1 deletion packages/connectivity/connectivity_macos/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: connectivity_macos
description: macOS implementation of the connectivity plugin.
version: 0.2.0
version: 0.2.1
homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity_macos

flutter:
plugin:
implements: connectivity
platforms:
macos:
pluginClass: ConnectivityPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@ import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_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:path_provider_windows/path_provider_windows.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

test('path provider instance on Windows', () {
expect(PathProviderPlatform.instance, isA<PathProviderWindows>());
}, skip: !Platform.isWindows);

test('path provider instance on Linux', () {
expect(PathProviderPlatform.instance, isA<PathProviderLinux>());
}, skip: !Platform.isLinux);

testWidgets('getTemporaryDirectory', (WidgetTester tester) async {
final Directory result = await getTemporaryDirectory();
_verifySampleFile(result, 'temporaryDirectory');
Expand Down
9 changes: 9 additions & 0 deletions packages/path_provider/path_provider/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ dependencies:
# the parent directory to use the current plugin's version.
path: ../

# TODO(egarciad): Remove the overrides once the packages are published.
dependency_overrides:
path_provider_macos:
path: ../../path_provider_macos
path_provider_linux:
path: ../../path_provider_linux
path_provider_windows:
path: ../../path_provider_windows

dev_dependencies:
integration_test:
sdk: flutter
Expand Down
51 changes: 16 additions & 35 deletions packages/path_provider/path_provider/lib/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io' show Directory, Platform;
import 'dart:async';
import 'dart:io' show Directory;

import 'package:flutter/foundation.dart' show kIsWeb, visibleForTesting;
import 'package:path_provider_linux/path_provider_linux.dart';
import 'package:flutter/foundation.dart' show visibleForTesting;
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
// ignore: implementation_imports
import 'package:path_provider_platform_interface/src/method_channel_path_provider.dart';
import 'package:path_provider_windows/path_provider_windows.dart';

export 'package:path_provider_platform_interface/path_provider_platform_interface.dart'
show StorageDirectory;
Expand All @@ -18,8 +15,6 @@ export 'package:path_provider_platform_interface/path_provider_platform_interfac
@Deprecated('This is no longer necessary, and is now a no-op')
set disablePathProviderPlatformOverride(bool override) {}

bool _manualDartRegistrationNeeded = true;

/// An exception thrown when a directory that should always be available on
/// the current platform cannot be obtained.
class MissingPlatformDirectoryException implements Exception {
Expand All @@ -41,25 +36,7 @@ class MissingPlatformDirectoryException implements Exception {
}
}

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;
}

return PathProviderPlatform.instance;
}
void main() {}

/// Path to the temporary directory on the device that is not backed up and is
/// suitable for storing caches of downloaded files.
Expand All @@ -76,7 +53,7 @@ PathProviderPlatform get _platform {
/// Throws a `MissingPlatformDirectoryException` if the system is unable to
/// provide the directory.
Future<Directory> getTemporaryDirectory() async {
final String? path = await _platform.getTemporaryPath();
final String? path = await PathProviderPlatform.instance.getTemporaryPath();
if (path == null) {
throw MissingPlatformDirectoryException(
'Unable to get temporary directory');
Expand All @@ -98,7 +75,8 @@ Future<Directory> getTemporaryDirectory() async {
/// Throws a `MissingPlatformDirectoryException` if the system is unable to
/// provide the directory.
Future<Directory> getApplicationSupportDirectory() async {
final String? path = await _platform.getApplicationSupportPath();
final String? path =
await PathProviderPlatform.instance.getApplicationSupportPath();
if (path == null) {
throw MissingPlatformDirectoryException(
'Unable to get application support directory');
Expand All @@ -116,7 +94,7 @@ Future<Directory> getApplicationSupportDirectory() async {
/// Throws a `MissingPlatformDirectoryException` if the system is unable to
/// provide the directory on a supported platform.
Future<Directory> getLibraryDirectory() async {
final String? path = await _platform.getLibraryPath();
final String? path = await PathProviderPlatform.instance.getLibraryPath();
if (path == null) {
throw MissingPlatformDirectoryException('Unable to get library directory');
}
Expand All @@ -136,7 +114,8 @@ Future<Directory> getLibraryDirectory() async {
/// Throws a `MissingPlatformDirectoryException` if the system is unable to
/// provide the directory.
Future<Directory> getApplicationDocumentsDirectory() async {
final String? path = await _platform.getApplicationDocumentsPath();
final String? path =
await PathProviderPlatform.instance.getApplicationDocumentsPath();
if (path == null) {
throw MissingPlatformDirectoryException(
'Unable to get application documents directory');
Expand All @@ -153,7 +132,8 @@ Future<Directory> getApplicationDocumentsDirectory() async {
///
/// On Android this uses the `getExternalFilesDir(null)`.
Future<Directory?> getExternalStorageDirectory() async {
final String? path = await _platform.getExternalStoragePath();
final String? path =
await PathProviderPlatform.instance.getExternalStoragePath();
if (path == null) {
return null;
}
Expand All @@ -174,7 +154,8 @@ Future<Directory?> getExternalStorageDirectory() async {
/// On Android this returns Context.getExternalCacheDirs() or
/// Context.getExternalCacheDir() on API levels below 19.
Future<List<Directory>?> getExternalCacheDirectories() async {
final List<String>? paths = await _platform.getExternalCachePaths();
final List<String>? paths =
await PathProviderPlatform.instance.getExternalCachePaths();
if (paths == null) {
return null;
}
Expand All @@ -200,7 +181,7 @@ Future<List<Directory>?> getExternalStorageDirectories({
StorageDirectory? type,
}) async {
final List<String>? paths =
await _platform.getExternalStoragePaths(type: type);
await PathProviderPlatform.instance.getExternalStoragePaths(type: type);
if (paths == null) {
return null;
}
Expand All @@ -214,7 +195,7 @@ Future<List<Directory>?> getExternalStorageDirectories({
/// On Android and on iOS, this function throws an [UnsupportedError] as no equivalent
/// path exists.
Future<Directory?> getDownloadsDirectory() async {
final String? path = await _platform.getDownloadsPath();
final String? path = await PathProviderPlatform.instance.getDownloadsPath();
if (path == null) {
return null;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/path_provider/path_provider_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.1

* Add `implements` to pubspec.yaml.
* Add `registerWith` method to the main Dart class.

## 2.0.0

* Migrate to null safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:xdg_directories/xdg_directories.dart' as xdg;
/// This class implements the `package:path_provider` functionality for linux
class PathProviderLinux extends PathProviderPlatform {
/// Registers this class as the default instance of [PathProviderPlatform]
static void register() {
static void registerWith() {
PathProviderPlatform.instance = PathProviderLinux();
}

Expand Down
3 changes: 2 additions & 1 deletion packages/path_provider/path_provider_linux/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: path_provider_linux
description: linux implementation of the path_provider plugin
version: 2.0.0
version: 2.0.1
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_linux

flutter:
plugin:
implements: path_provider
platforms:
linux:
dartPluginClass: PathProviderLinux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:path_provider_platform_interface/path_provider_platform_interfac

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
PathProviderLinux.register();
PathProviderLinux.registerWith();

setUp(() {});

Expand Down
4 changes: 4 additions & 0 deletions packages/path_provider/path_provider_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.1

* Add `implements` to pubspec.ymal.

## 2.0.0

* Update Dart SDK constraint for null safety compatibility.
Expand Down
3 changes: 2 additions & 1 deletion packages/path_provider/path_provider_macos/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: path_provider_macos
description: macOS implementation of the path_provider plugin
version: 2.0.0
version: 2.0.1
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_macos

flutter:
plugin:
implements: path_provider
platforms:
macos:
pluginClass: PathProviderPlugin
Expand Down
5 changes: 5 additions & 0 deletions packages/path_provider/path_provider_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.2

* Add `implements` to pubspec.yaml.
* Add `registerWith()` to the Dart main class.

## 2.0.1

* Fix a crash when a known folder can't be located.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class VersionInfoQuerier {
///
/// This class implements the `package:path_provider` functionality for Windows.
class PathProviderWindows extends PathProviderPlatform {
/// Registers the Windows implementation.
static void registerWith() {
PathProviderPlatform.instance = PathProviderWindows();
}

/// The object to use for performing VerQueryValue calls.
@visibleForTesting
VersionInfoQuerier versionInfoQuerier = VersionInfoQuerier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class PathProviderWindows extends PathProviderPlatform {
/// compile-time dependencies, and should never actually be created.
PathProviderWindows() : assert(false);

/// Registers the Windows implementation.
static void registerWith() {
PathProviderPlatform.instance = PathProviderWindows();
}

/// Stub; see comment on VersionInfoQuerier.
VersionInfoQuerier versionInfoQuerier = VersionInfoQuerier();

Expand Down
3 changes: 2 additions & 1 deletion packages/path_provider/path_provider_windows/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: path_provider_windows
description: Windows implementation of the path_provider plugin
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_windows
version: 2.0.1
version: 2.0.2

flutter:
plugin:
implements: path_provider
platforms:
windows:
dartPluginClass: PathProviderWindows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ dev_dependencies:
sdk: flutter
pedantic: ^1.10.0

# TODO(egarciad): Bump dependencies above and remove the overrides.
dependency_overrides:
shared_preferences_linux:
path: ../../shared_preferences_linux
shared_preferences_macos:
path: ../../shared_preferences_macos
shared_preferences_windows:
path: ../../shared_preferences_windows

flutter:
uses-material-design: true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:io' show Platform;

import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:meta/meta.dart';
import 'package:shared_preferences_linux/shared_preferences_linux.dart';
import 'package:shared_preferences_platform_interface/method_channel_shared_preferences.dart';
import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart';
import 'package:shared_preferences_windows/shared_preferences_windows.dart';

/// Wraps NSUserDefaults (on iOS) and SharedPreferences (on Android), providing
/// a persistent store for simple data.
Expand All @@ -21,29 +16,6 @@ class SharedPreferences {

static const String _prefix = 'flutter.';
static Completer<SharedPreferences>? _completer;
static bool _manualDartRegistrationNeeded = true;

static SharedPreferencesStorePlatform get _store {
// This is to manually endorse the Linux implementation 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 &&
SharedPreferencesStorePlatform.instance
is MethodChannelSharedPreferencesStore) {
if (Platform.isLinux) {
SharedPreferencesStorePlatform.instance = SharedPreferencesLinux();
} else if (Platform.isWindows) {
SharedPreferencesStorePlatform.instance = SharedPreferencesWindows();
}
}
_manualDartRegistrationNeeded = false;
}

return SharedPreferencesStorePlatform.instance;
}

/// Loads and parses the [SharedPreferences] for this app from disk.
///
Expand Down Expand Up @@ -140,7 +112,7 @@ class SharedPreferences {
Future<bool> remove(String key) {
final String prefixedKey = '$_prefix$key';
_preferenceCache.remove(key);
return _store.remove(prefixedKey);
return SharedPreferencesStorePlatform.instance.remove(prefixedKey);
}

Future<bool> _setValue(String valueType, String key, Object value) {
Expand All @@ -152,7 +124,8 @@ class SharedPreferences {
} else {
_preferenceCache[key] = value;
}
return _store.setValue(valueType, prefixedKey, value);
return SharedPreferencesStorePlatform.instance
.setValue(valueType, prefixedKey, value);
}

/// Always returns true.
Expand All @@ -163,7 +136,7 @@ class SharedPreferences {
/// Completes with true once the user preferences for the app has been cleared.
Future<bool> clear() {
_preferenceCache.clear();
return _store.clear();
return SharedPreferencesStorePlatform.instance.clear();
}

/// Fetches the latest values from the host platform.
Expand All @@ -178,7 +151,8 @@ class SharedPreferences {
}

static Future<Map<String, Object>> _getSharedPreferencesMap() async {
final Map<String, Object> fromSystem = await _store.getAll();
final Map<String, Object> fromSystem =
await SharedPreferencesStorePlatform.instance.getAll();
assert(fromSystem != null);
// Strip the flutter. prefix from the returned preferences.
final Map<String, Object> preferencesMap = <String, Object>{};
Expand Down
Loading