diff --git a/packages/connectivity/connectivity_macos/CHANGELOG.md b/packages/connectivity/connectivity_macos/CHANGELOG.md index 7031e48318dd..0d962362a99f 100644 --- a/packages/connectivity/connectivity_macos/CHANGELOG.md +++ b/packages/connectivity/connectivity_macos/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.1 + +* Add `implements` to pubspec.yaml. + ## 0.2.0 * Remove placeholder Dart file. diff --git a/packages/connectivity/connectivity_macos/pubspec.yaml b/packages/connectivity/connectivity_macos/pubspec.yaml index b78db9baa0d2..fbef59350e2f 100644 --- a/packages/connectivity/connectivity_macos/pubspec.yaml +++ b/packages/connectivity/connectivity_macos/pubspec.yaml @@ -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 diff --git a/packages/path_provider/path_provider/example/integration_test/path_provider_test.dart b/packages/path_provider/path_provider/example/integration_test/path_provider_test.dart index 120abcbe4143..acdec5f17f25 100644 --- a/packages/path_provider/path_provider/example/integration_test/path_provider_test.dart +++ b/packages/path_provider/path_provider/example/integration_test/path_provider_test.dart @@ -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()); + }, skip: !Platform.isWindows); + + test('path provider instance on Linux', () { + expect(PathProviderPlatform.instance, isA()); + }, skip: !Platform.isLinux); + testWidgets('getTemporaryDirectory', (WidgetTester tester) async { final Directory result = await getTemporaryDirectory(); _verifySampleFile(result, 'temporaryDirectory'); diff --git a/packages/path_provider/path_provider/example/pubspec.yaml b/packages/path_provider/path_provider/example/pubspec.yaml index cf9f3dc8d6cf..9f38fe4e4ea3 100644 --- a/packages/path_provider/path_provider/example/pubspec.yaml +++ b/packages/path_provider/path_provider/example/pubspec.yaml @@ -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 diff --git a/packages/path_provider/path_provider/lib/path_provider.dart b/packages/path_provider/path_provider/lib/path_provider.dart index 341b09f4a314..d00bd3ec0333 100644 --- a/packages/path_provider/path_provider/lib/path_provider.dart +++ b/packages/path_provider/path_provider/lib/path_provider.dart @@ -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; @@ -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 { @@ -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. @@ -76,7 +53,7 @@ PathProviderPlatform get _platform { /// Throws a `MissingPlatformDirectoryException` if the system is unable to /// provide the directory. Future 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'); @@ -98,7 +75,8 @@ Future getTemporaryDirectory() async { /// Throws a `MissingPlatformDirectoryException` if the system is unable to /// provide the directory. Future 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'); @@ -116,7 +94,7 @@ Future getApplicationSupportDirectory() async { /// Throws a `MissingPlatformDirectoryException` if the system is unable to /// provide the directory on a supported platform. Future 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'); } @@ -136,7 +114,8 @@ Future getLibraryDirectory() async { /// Throws a `MissingPlatformDirectoryException` if the system is unable to /// provide the directory. Future 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'); @@ -153,7 +132,8 @@ Future getApplicationDocumentsDirectory() async { /// /// On Android this uses the `getExternalFilesDir(null)`. Future getExternalStorageDirectory() async { - final String? path = await _platform.getExternalStoragePath(); + final String? path = + await PathProviderPlatform.instance.getExternalStoragePath(); if (path == null) { return null; } @@ -174,7 +154,8 @@ Future getExternalStorageDirectory() async { /// On Android this returns Context.getExternalCacheDirs() or /// Context.getExternalCacheDir() on API levels below 19. Future?> getExternalCacheDirectories() async { - final List? paths = await _platform.getExternalCachePaths(); + final List? paths = + await PathProviderPlatform.instance.getExternalCachePaths(); if (paths == null) { return null; } @@ -200,7 +181,7 @@ Future?> getExternalStorageDirectories({ StorageDirectory? type, }) async { final List? paths = - await _platform.getExternalStoragePaths(type: type); + await PathProviderPlatform.instance.getExternalStoragePaths(type: type); if (paths == null) { return null; } @@ -214,7 +195,7 @@ Future?> getExternalStorageDirectories({ /// On Android and on iOS, this function throws an [UnsupportedError] as no equivalent /// path exists. Future getDownloadsDirectory() async { - final String? path = await _platform.getDownloadsPath(); + final String? path = await PathProviderPlatform.instance.getDownloadsPath(); if (path == null) { return null; } diff --git a/packages/path_provider/path_provider_linux/CHANGELOG.md b/packages/path_provider/path_provider_linux/CHANGELOG.md index a85c6bbb4ef3..9383181d6a76 100644 --- a/packages/path_provider/path_provider_linux/CHANGELOG.md +++ b/packages/path_provider/path_provider_linux/CHANGELOG.md @@ -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. diff --git a/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart b/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart index 5a81114cc92d..38800bee1f2e 100644 --- a/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart +++ b/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart @@ -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(); } diff --git a/packages/path_provider/path_provider_linux/pubspec.yaml b/packages/path_provider/path_provider_linux/pubspec.yaml index 5d1c395aa418..b5bea8754dbe 100644 --- a/packages/path_provider/path_provider_linux/pubspec.yaml +++ b/packages/path_provider/path_provider_linux/pubspec.yaml @@ -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 diff --git a/packages/path_provider/path_provider_linux/test/path_provider_linux_test.dart b/packages/path_provider/path_provider_linux/test/path_provider_linux_test.dart index 3384a3d2f963..3ff3aa90b518 100644 --- a/packages/path_provider/path_provider_linux/test/path_provider_linux_test.dart +++ b/packages/path_provider/path_provider_linux/test/path_provider_linux_test.dart @@ -7,7 +7,7 @@ import 'package:path_provider_platform_interface/path_provider_platform_interfac void main() { TestWidgetsFlutterBinding.ensureInitialized(); - PathProviderLinux.register(); + PathProviderLinux.registerWith(); setUp(() {}); diff --git a/packages/path_provider/path_provider_macos/CHANGELOG.md b/packages/path_provider/path_provider_macos/CHANGELOG.md index f989efbe2a98..c77e1a1bdb64 100644 --- a/packages/path_provider/path_provider_macos/CHANGELOG.md +++ b/packages/path_provider/path_provider_macos/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.1 + +* Add `implements` to pubspec.ymal. + ## 2.0.0 * Update Dart SDK constraint for null safety compatibility. diff --git a/packages/path_provider/path_provider_macos/pubspec.yaml b/packages/path_provider/path_provider_macos/pubspec.yaml index 522ef0a369af..3ebe43e62d9c 100644 --- a/packages/path_provider/path_provider_macos/pubspec.yaml +++ b/packages/path_provider/path_provider_macos/pubspec.yaml @@ -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 diff --git a/packages/path_provider/path_provider_windows/CHANGELOG.md b/packages/path_provider/path_provider_windows/CHANGELOG.md index 02c3b2300fc0..2e4da0e1f353 100644 --- a/packages/path_provider/path_provider_windows/CHANGELOG.md +++ b/packages/path_provider/path_provider_windows/CHANGELOG.md @@ -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. diff --git a/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart b/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart index 971967373438..2b87d51c1c49 100644 --- a/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart +++ b/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart @@ -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(); diff --git a/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_stub.dart b/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_stub.dart index 91334d95ae24..bc851831bf54 100644 --- a/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_stub.dart +++ b/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_stub.dart @@ -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(); diff --git a/packages/path_provider/path_provider_windows/pubspec.yaml b/packages/path_provider/path_provider_windows/pubspec.yaml index d0badefc8d7e..067fec4ceb78 100644 --- a/packages/path_provider/path_provider_windows/pubspec.yaml +++ b/packages/path_provider/path_provider_windows/pubspec.yaml @@ -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 diff --git a/packages/shared_preferences/shared_preferences/example/pubspec.yaml b/packages/shared_preferences/shared_preferences/example/pubspec.yaml index a2493aa04ce9..afaee6fe7722 100644 --- a/packages/shared_preferences/shared_preferences/example/pubspec.yaml +++ b/packages/shared_preferences/shared_preferences/example/pubspec.yaml @@ -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 diff --git a/packages/shared_preferences/shared_preferences/lib/shared_preferences.dart b/packages/shared_preferences/shared_preferences/lib/shared_preferences.dart index 493e38901ddf..d54a053d5e27 100644 --- a/packages/shared_preferences/shared_preferences/lib/shared_preferences.dart +++ b/packages/shared_preferences/shared_preferences/lib/shared_preferences.dart @@ -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. @@ -21,29 +16,6 @@ class SharedPreferences { static const String _prefix = 'flutter.'; static Completer? _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. /// @@ -140,7 +112,7 @@ class SharedPreferences { Future remove(String key) { final String prefixedKey = '$_prefix$key'; _preferenceCache.remove(key); - return _store.remove(prefixedKey); + return SharedPreferencesStorePlatform.instance.remove(prefixedKey); } Future _setValue(String valueType, String key, Object value) { @@ -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. @@ -163,7 +136,7 @@ class SharedPreferences { /// Completes with true once the user preferences for the app has been cleared. Future clear() { _preferenceCache.clear(); - return _store.clear(); + return SharedPreferencesStorePlatform.instance.clear(); } /// Fetches the latest values from the host platform. @@ -178,7 +151,8 @@ class SharedPreferences { } static Future> _getSharedPreferencesMap() async { - final Map fromSystem = await _store.getAll(); + final Map fromSystem = + await SharedPreferencesStorePlatform.instance.getAll(); assert(fromSystem != null); // Strip the flutter. prefix from the returned preferences. final Map preferencesMap = {}; diff --git a/packages/shared_preferences/shared_preferences_linux/CHANGELOG.md b/packages/shared_preferences/shared_preferences_linux/CHANGELOG.md index a50b4e470c53..9a17d2455ad8 100644 --- a/packages/shared_preferences/shared_preferences_linux/CHANGELOG.md +++ b/packages/shared_preferences/shared_preferences_linux/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.1 + +* Add `implements` to the pubspec. +* Add `registerWith` to the Dart main class. + ## 2.0.0 * Migrate to null-safety. diff --git a/packages/shared_preferences/shared_preferences_linux/example/integration_test/shared_preferences_test.dart b/packages/shared_preferences/shared_preferences_linux/example/integration_test/shared_preferences_test.dart index ab32552b4918..4763c4d669e0 100644 --- a/packages/shared_preferences/shared_preferences_linux/example/integration_test/shared_preferences_test.dart +++ b/packages/shared_preferences/shared_preferences_linux/example/integration_test/shared_preferences_test.dart @@ -9,6 +9,7 @@ import 'dart:async'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:shared_preferences_linux/shared_preferences_linux.dart'; +import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart'; void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); @@ -30,14 +31,18 @@ void main() { 'flutter.List': ['baz', 'quox'], }; - SharedPreferencesLinux preferences; + SharedPreferencesStorePlatform preferences; - setUp(() async { - preferences = SharedPreferencesLinux.instance; + setUp(() { + preferences = SharedPreferencesStorePlatform.instance; }); - tearDown(() { - preferences.clear(); + tearDown(() async { + await preferences.clear(); + }); + + test('instance is Linux implementation', () { + expect(preferences, isA()); }); testWidgets('reading', (WidgetTester _) async { diff --git a/packages/shared_preferences/shared_preferences_linux/example/lib/main.dart b/packages/shared_preferences/shared_preferences_linux/example/lib/main.dart index aee71d00d44d..3e985bc18105 100644 --- a/packages/shared_preferences/shared_preferences_linux/example/lib/main.dart +++ b/packages/shared_preferences/shared_preferences_linux/example/lib/main.dart @@ -7,7 +7,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:shared_preferences_linux/shared_preferences_linux.dart'; +import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart'; void main() { runApp(MyApp()); @@ -31,7 +31,7 @@ class SharedPreferencesDemo extends StatefulWidget { } class SharedPreferencesDemoState extends State { - final prefs = SharedPreferencesLinux.instance; + final prefs = SharedPreferencesStorePlatform.instance; late Future _counter; Future _incrementCounter() async { diff --git a/packages/shared_preferences/shared_preferences_linux/lib/shared_preferences_linux.dart b/packages/shared_preferences/shared_preferences_linux/lib/shared_preferences_linux.dart index e4fc24e78cff..4a954336dae9 100644 --- a/packages/shared_preferences/shared_preferences_linux/lib/shared_preferences_linux.dart +++ b/packages/shared_preferences/shared_preferences_linux/lib/shared_preferences_linux.dart @@ -16,8 +16,10 @@ import 'package:shared_preferences_platform_interface/shared_preferences_platfor /// /// This class implements the `package:shared_preferences` functionality for Linux. class SharedPreferencesLinux extends SharedPreferencesStorePlatform { - /// The default instance of [SharedPreferencesLinux] to use. - static SharedPreferencesLinux instance = SharedPreferencesLinux(); + /// Registers the Linux implementation. + static void registerWith() { + SharedPreferencesStorePlatform.instance = SharedPreferencesLinux(); + } /// Local copy of preferences Map? _cachedPreferences; diff --git a/packages/shared_preferences/shared_preferences_linux/pubspec.yaml b/packages/shared_preferences/shared_preferences_linux/pubspec.yaml index a573b7cff438..d3bbc1e22363 100644 --- a/packages/shared_preferences/shared_preferences_linux/pubspec.yaml +++ b/packages/shared_preferences/shared_preferences_linux/pubspec.yaml @@ -1,10 +1,11 @@ name: shared_preferences_linux description: Linux implementation of the shared_preferences plugin -version: 2.0.0 +version: 2.0.1 homepage: https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences_linux flutter: plugin: + implements: shared_preferences platforms: linux: dartPluginClass: SharedPreferencesLinux diff --git a/packages/shared_preferences/shared_preferences_macos/CHANGELOG.md b/packages/shared_preferences/shared_preferences_macos/CHANGELOG.md index 00c2f628796f..ac8dd2c4752b 100644 --- a/packages/shared_preferences/shared_preferences_macos/CHANGELOG.md +++ b/packages/shared_preferences/shared_preferences_macos/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.1 + +* Add `implements` to the pubspec. + ## 2.0.0 * Migrate to null safety. diff --git a/packages/shared_preferences/shared_preferences_macos/example/integration_test/shared_preferences_test.dart b/packages/shared_preferences/shared_preferences_macos/example/integration_test/shared_preferences_test.dart index 722aee3da50a..295689a1d33f 100644 --- a/packages/shared_preferences/shared_preferences_macos/example/integration_test/shared_preferences_test.dart +++ b/packages/shared_preferences/shared_preferences_macos/example/integration_test/shared_preferences_test.dart @@ -31,7 +31,7 @@ void main() { SharedPreferencesStorePlatform preferences; - setUp(() async { + setUp(() { preferences = SharedPreferencesStorePlatform.instance; }); diff --git a/packages/shared_preferences/shared_preferences_macos/pubspec.yaml b/packages/shared_preferences/shared_preferences_macos/pubspec.yaml index b1c883352452..6a5c8c006dbd 100644 --- a/packages/shared_preferences/shared_preferences_macos/pubspec.yaml +++ b/packages/shared_preferences/shared_preferences_macos/pubspec.yaml @@ -1,10 +1,11 @@ name: shared_preferences_macos description: macOS implementation of the shared_preferences plugin. -version: 2.0.0 +version: 2.0.1 homepage: https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences_macos flutter: plugin: + implements: shared_preferences platforms: macos: pluginClass: SharedPreferencesPlugin diff --git a/packages/shared_preferences/shared_preferences_windows/CHANGELOG.md b/packages/shared_preferences/shared_preferences_windows/CHANGELOG.md index 6fa4eb162083..a8b1a6344f47 100644 --- a/packages/shared_preferences/shared_preferences_windows/CHANGELOG.md +++ b/packages/shared_preferences/shared_preferences_windows/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.1 + +* Add `implements` to the pubspec. +* Add `registerWith` to the Dart main class. + ## 2.0.0 * Migrate to null-safety. diff --git a/packages/shared_preferences/shared_preferences_windows/example/integration_test/shared_preferences_test.dart b/packages/shared_preferences/shared_preferences_windows/example/integration_test/shared_preferences_test.dart index 6b3e9e76fffd..2531b3048192 100644 --- a/packages/shared_preferences/shared_preferences_windows/example/integration_test/shared_preferences_test.dart +++ b/packages/shared_preferences/shared_preferences_windows/example/integration_test/shared_preferences_test.dart @@ -4,10 +4,9 @@ // @dart=2.9 -import 'dart:async'; import 'package:flutter_test/flutter_test.dart'; -import 'package:shared_preferences_windows/shared_preferences_windows.dart'; import 'package:integration_test/integration_test.dart'; +import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart'; void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); @@ -29,14 +28,16 @@ void main() { 'flutter.List': ['baz', 'quox'], }; - SharedPreferencesWindows preferences; + SharedPreferencesStorePlatform preferences; - setUp(() async { - preferences = SharedPreferencesWindows.instance; + setUp(() { + preferences = SharedPreferencesStorePlatform.instance; + expect(preferences.runtimeType.toString(), + equals('SharedPreferencesWindows')); }); - tearDown(() { - preferences.clear(); + tearDown(() async { + expect(await preferences.clear(), isTrue); }); testWidgets('reading', (WidgetTester _) async { @@ -49,15 +50,31 @@ void main() { }); testWidgets('writing', (WidgetTester _) async { - await Future.wait(>[ - preferences.setValue( + expect( + await preferences.setValue( 'String', 'String', kTestValues2['flutter.String']), - preferences.setValue('Bool', 'bool', kTestValues2['flutter.bool']), - preferences.setValue('Int', 'int', kTestValues2['flutter.int']), - preferences.setValue( + isTrue, + ); + expect( + await preferences.setValue( + 'Bool', 'bool', kTestValues2['flutter.bool']), + isTrue, + ); + expect( + await preferences.setValue('Int', 'int', kTestValues2['flutter.int']), + isTrue, + ); + expect( + await preferences.setValue( 'Double', 'double', kTestValues2['flutter.double']), - preferences.setValue('StringList', 'List', kTestValues2['flutter.List']) - ]); + isTrue, + ); + expect( + await preferences.setValue( + 'StringList', 'List', kTestValues2['flutter.List']), + isTrue, + ); + final Map values = await preferences.getAll(); expect(values['String'], kTestValues2['flutter.String']); expect(values['bool'], kTestValues2['flutter.bool']); diff --git a/packages/shared_preferences/shared_preferences_windows/example/lib/main.dart b/packages/shared_preferences/shared_preferences_windows/example/lib/main.dart index 0cdd37394706..3e985bc18105 100644 --- a/packages/shared_preferences/shared_preferences_windows/example/lib/main.dart +++ b/packages/shared_preferences/shared_preferences_windows/example/lib/main.dart @@ -7,7 +7,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:shared_preferences_windows/shared_preferences_windows.dart'; +import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart'; void main() { runApp(MyApp()); @@ -31,7 +31,7 @@ class SharedPreferencesDemo extends StatefulWidget { } class SharedPreferencesDemoState extends State { - final prefs = SharedPreferencesWindows.instance; + final prefs = SharedPreferencesStorePlatform.instance; late Future _counter; Future _incrementCounter() async { diff --git a/packages/shared_preferences/shared_preferences_windows/example/pubspec.yaml b/packages/shared_preferences/shared_preferences_windows/example/pubspec.yaml index a2b41ef1d3ac..8f348ebe8114 100644 --- a/packages/shared_preferences/shared_preferences_windows/example/pubspec.yaml +++ b/packages/shared_preferences/shared_preferences_windows/example/pubspec.yaml @@ -9,6 +9,7 @@ environment: dependencies: flutter: sdk: flutter + shared_preferences_platform_interface: ^2.0.0 shared_preferences_windows: ^2.0.0 dependency_overrides: diff --git a/packages/shared_preferences/shared_preferences_windows/lib/shared_preferences_windows.dart b/packages/shared_preferences/shared_preferences_windows/lib/shared_preferences_windows.dart index 8bbda6ec139a..c1cb571d29d4 100644 --- a/packages/shared_preferences/shared_preferences_windows/lib/shared_preferences_windows.dart +++ b/packages/shared_preferences/shared_preferences_windows/lib/shared_preferences_windows.dart @@ -15,8 +15,10 @@ import 'package:path_provider_windows/path_provider_windows.dart'; /// /// This class implements the `package:shared_preferences` functionality for Windows. class SharedPreferencesWindows extends SharedPreferencesStorePlatform { - /// The default instance of [SharedPreferencesWindows] to use. - static SharedPreferencesWindows instance = SharedPreferencesWindows(); + /// Registers the Windows implementation. + static void registerWith() { + SharedPreferencesStorePlatform.instance = SharedPreferencesWindows(); + } /// File system used to store to disk. Exposed for testing only. @visibleForTesting diff --git a/packages/shared_preferences/shared_preferences_windows/pubspec.yaml b/packages/shared_preferences/shared_preferences_windows/pubspec.yaml index cafb6b767045..4e8327cadb33 100644 --- a/packages/shared_preferences/shared_preferences_windows/pubspec.yaml +++ b/packages/shared_preferences/shared_preferences_windows/pubspec.yaml @@ -1,11 +1,11 @@ name: shared_preferences_windows description: Windows implementation of shared_preferences homepage: https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences_windows -version: 2.0.0 - +version: 2.0.1 flutter: plugin: + implements: shared_preferences platforms: windows: dartPluginClass: SharedPreferencesWindows