Skip to content

Commit c54b73d

Browse files
author
Emmanuel Garcia
authored
Add implement and registerWith method to plugins (flutter#3833)
1 parent f13a39e commit c54b73d

File tree

25 files changed

+107
-23
lines changed

25 files changed

+107
-23
lines changed

packages/connectivity/connectivity_macos/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.1
2+
3+
* Add `implements` to pubspec.yaml.
4+
15
## 0.2.0
26

37
* Remove placeholder Dart file.

packages/connectivity/connectivity_macos/pubspec.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: connectivity_macos
22
description: macOS implementation of the connectivity plugin.
3-
version: 0.2.0
3+
version: 0.2.1
44
homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity_macos
55

66
flutter:
77
plugin:
8+
implements: connectivity_platform_interface
89
platforms:
910
macos:
1011
pluginClass: ConnectivityPlugin
@@ -16,6 +17,13 @@ environment:
1617
dependencies:
1718
flutter:
1819
sdk: flutter
20+
# The implementation of this plugin doesn't explicitly depend on the method channel
21+
# defined in the platform interface.
22+
# To prevent potential breakages, this dependency is added.
23+
#
24+
# In the future, this plugin's platform code should be able to reference the
25+
# interface's platform code. (Android already supports this).
26+
connectivity_platform_interface: ^2.0.0
1927

2028
dev_dependencies:
2129
pedantic: ^1.10.0

packages/path_provider/path_provider/lib/path_provider.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ class MissingPlatformDirectoryException implements Exception {
4242
}
4343

4444
PathProviderPlatform get _platform {
45-
// This is to manually endorse Dart implementations until automatic
46-
// registration of Dart plugins is implemented. For details see
47-
// https://github.com/flutter/flutter/issues/52267.
45+
// TODO(egarciad): Remove once auto registration lands on Flutter stable.
46+
// https://github.com/flutter/flutter/issues/81421.
4847
if (_manualDartRegistrationNeeded) {
4948
// Only do the initial registration if it hasn't already been overridden
5049
// with a non-default instance.

packages/path_provider/path_provider_linux/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.0.1
2+
3+
* Add `implements` to pubspec.yaml.
4+
* Add `registerWith` method to the main Dart class.
5+
16
## 2.0.0
27

38
* Migrate to null safety.

packages/path_provider/path_provider_linux/lib/path_provider_linux.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:xdg_directories/xdg_directories.dart' as xdg;
1313
/// This class implements the `package:path_provider` functionality for linux
1414
class PathProviderLinux extends PathProviderPlatform {
1515
/// Registers this class as the default instance of [PathProviderPlatform]
16-
static void register() {
16+
static void registerWith() {
1717
PathProviderPlatform.instance = PathProviderLinux();
1818
}
1919

packages/path_provider/path_provider_linux/pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: path_provider_linux
22
description: linux implementation of the path_provider plugin
3-
version: 2.0.0
3+
version: 2.0.1
44
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_linux
55

66
flutter:
77
plugin:
8+
implements: path_provider
89
platforms:
910
linux:
1011
dartPluginClass: PathProviderLinux

packages/path_provider/path_provider_linux/test/path_provider_linux_test.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import 'package:path_provider_platform_interface/path_provider_platform_interfac
77

88
void main() {
99
TestWidgetsFlutterBinding.ensureInitialized();
10-
PathProviderLinux.register();
10+
PathProviderLinux.registerWith();
1111

12-
setUp(() {});
13-
14-
tearDown(() {});
12+
test('registered instance', () {
13+
expect(PathProviderPlatform.instance, isA<PathProviderLinux>());
14+
});
1515

1616
test('getTemporaryPath', () async {
1717
final PathProviderPlatform plugin = PathProviderPlatform.instance;

packages/path_provider/path_provider_macos/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.1
2+
3+
* Add `implements` to pubspec.yaml.
4+
15
## 2.0.0
26

37
* Update Dart SDK constraint for null safety compatibility.

packages/path_provider/path_provider_macos/pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: path_provider_macos
22
description: macOS implementation of the path_provider plugin
3-
version: 2.0.0
3+
version: 2.0.1
44
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_macos
55

66
flutter:
77
plugin:
8+
implements: path_provider
89
platforms:
910
macos:
1011
pluginClass: PathProviderPlugin

packages/path_provider/path_provider_windows/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.0.2
2+
3+
* Add `implements` to pubspec.yaml.
4+
* Add `registerWith()` to the Dart main class.
5+
16
## 2.0.1
27

38
* Fix a crash when a known folder can't be located.

packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ class VersionInfoQuerier {
4747
///
4848
/// This class implements the `package:path_provider` functionality for Windows.
4949
class PathProviderWindows extends PathProviderPlatform {
50+
/// Registers the Windows implementation.
51+
static void registerWith() {
52+
PathProviderPlatform.instance = PathProviderWindows();
53+
}
54+
5055
/// The object to use for performing VerQueryValue calls.
5156
@visibleForTesting
5257
VersionInfoQuerier versionInfoQuerier = VersionInfoQuerier();

packages/path_provider/path_provider_windows/lib/src/path_provider_windows_stub.dart

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ class PathProviderWindows extends PathProviderPlatform {
1616
/// compile-time dependencies, and should never actually be created.
1717
PathProviderWindows() : assert(false);
1818

19+
/// Registers the Windows implementation.
20+
static void registerWith() {
21+
PathProviderPlatform.instance = PathProviderWindows();
22+
}
23+
1924
/// Stub; see comment on VersionInfoQuerier.
2025
VersionInfoQuerier versionInfoQuerier = VersionInfoQuerier();
2126

packages/path_provider/path_provider_windows/pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: path_provider_windows
22
description: Windows implementation of the path_provider plugin
33
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_windows
4-
version: 2.0.1
4+
version: 2.0.2
55

66
flutter:
77
plugin:
8+
implements: path_provider
89
platforms:
910
windows:
1011
dartPluginClass: PathProviderWindows

packages/path_provider/path_provider_windows/test/path_provider_windows_test.dart

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'dart:ffi';
55
import 'dart:io';
66

77
import 'package:flutter_test/flutter_test.dart';
8+
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
89
import 'package:path_provider_windows/path_provider_windows.dart';
910

1011
// A fake VersionInfoQuerier that just returns preset responses.
@@ -18,6 +19,11 @@ class FakeVersionInfoQuerier implements VersionInfoQuerier {
1819
}
1920

2021
void main() {
22+
test('registered instance', () {
23+
PathProviderWindows.registerWith();
24+
expect(PathProviderPlatform.instance, isA<PathProviderWindows>());
25+
});
26+
2127
test('getTemporaryPath', () async {
2228
final PathProviderWindows pathProvider = PathProviderWindows();
2329
expect(await pathProvider.getTemporaryPath(), contains(r'C:\'));

packages/shared_preferences/shared_preferences/lib/shared_preferences.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ class SharedPreferences {
2424
static bool _manualDartRegistrationNeeded = true;
2525

2626
static SharedPreferencesStorePlatform get _store {
27-
// This is to manually endorse the Linux implementation until automatic
28-
// registration of dart plugins is implemented. For details see
29-
// https://github.com/flutter/flutter/issues/52267.
27+
// TODO(egarciad): Remove once auto registration lands on Flutter stable.
28+
// https://github.com/flutter/flutter/issues/81421.
3029
if (_manualDartRegistrationNeeded) {
3130
// Only do the initial registration if it hasn't already been overridden
3231
// with a non-default instance.

packages/shared_preferences/shared_preferences_linux/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.0.1
2+
3+
* Add `implements` to the pubspec.
4+
* Add `registerWith` to the Dart main class.
5+
16
## 2.0.0
27

38
* Migrate to null-safety.

packages/shared_preferences/shared_preferences_linux/lib/shared_preferences_linux.dart

+7
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ import 'package:shared_preferences_platform_interface/shared_preferences_platfor
1717
/// This class implements the `package:shared_preferences` functionality for Linux.
1818
class SharedPreferencesLinux extends SharedPreferencesStorePlatform {
1919
/// The default instance of [SharedPreferencesLinux] to use.
20+
/// TODO(egarciad): Remove when the Dart plugin registrant lands on Flutter stable.
21+
/// https://github.com/flutter/flutter/issues/81421
2022
static SharedPreferencesLinux instance = SharedPreferencesLinux();
2123

24+
/// Registers the Linux implementation.
25+
static void registerWith() {
26+
SharedPreferencesStorePlatform.instance = instance;
27+
}
28+
2229
/// Local copy of preferences
2330
Map<String, Object>? _cachedPreferences;
2431

packages/shared_preferences/shared_preferences_linux/pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: shared_preferences_linux
22
description: Linux implementation of the shared_preferences plugin
3-
version: 2.0.0
3+
version: 2.0.1
44
homepage: https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences_linux
55

66
flutter:
77
plugin:
8+
implements: shared_preferences
89
platforms:
910
linux:
1011
dartPluginClass: SharedPreferencesLinux

packages/shared_preferences/shared_preferences_linux/test/shared_preferences_linux_test.dart

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import 'package:flutter_test/flutter_test.dart';
66
import 'package:path/path.dart' as path;
77
import 'package:path_provider_linux/path_provider_linux.dart';
88
import 'package:shared_preferences_linux/shared_preferences_linux.dart';
9+
import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart';
910

1011
void main() {
1112
late MemoryFileSystem fs;
1213

14+
SharedPreferencesLinux.registerWith();
15+
1316
setUp(() {
1417
fs = MemoryFileSystem.test();
1518
});
1619

17-
tearDown(() {});
18-
1920
Future<String> _getFilePath() async {
2021
final pathProvider = PathProviderLinux();
2122
final directory = await pathProvider.getApplicationSupportPath();
@@ -38,6 +39,11 @@ void main() {
3839
return prefs;
3940
}
4041

42+
test('registered instance', () {
43+
expect(
44+
SharedPreferencesStorePlatform.instance, isA<SharedPreferencesLinux>());
45+
});
46+
4147
test('getAll', () async {
4248
await _writeTestFile('{"key1": "one", "key2": 2}');
4349
var prefs = _getPreferences();

packages/shared_preferences/shared_preferences_macos/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.1
2+
3+
* Add `implements` to the pubspec.
4+
15
## 2.0.0
26

37
* Migrate to null safety.

packages/shared_preferences/shared_preferences_macos/pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: shared_preferences_macos
22
description: macOS implementation of the shared_preferences plugin.
3-
version: 2.0.0
3+
version: 2.0.1
44
homepage: https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences_macos
55

66
flutter:
77
plugin:
8+
implements: shared_preferences
89
platforms:
910
macos:
1011
pluginClass: SharedPreferencesPlugin

packages/shared_preferences/shared_preferences_windows/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.0.1
2+
3+
* Add `implements` to pubspec.yaml.
4+
* Add `registerWith` to the Dart main class.
5+
16
## 2.0.0
27

38
* Migrate to null-safety.

packages/shared_preferences/shared_preferences_windows/lib/shared_preferences_windows.dart

+7
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@ import 'package:path_provider_windows/path_provider_windows.dart';
1616
/// This class implements the `package:shared_preferences` functionality for Windows.
1717
class SharedPreferencesWindows extends SharedPreferencesStorePlatform {
1818
/// The default instance of [SharedPreferencesWindows] to use.
19+
/// TODO(egarciad): Remove when the Dart plugin registrant lands on Flutter stable.
20+
/// https://github.com/flutter/flutter/issues/81421
1921
static SharedPreferencesWindows instance = SharedPreferencesWindows();
2022

23+
/// Registers the Windows implementation.
24+
static void registerWith() {
25+
SharedPreferencesStorePlatform.instance = instance;
26+
}
27+
2128
/// File system used to store to disk. Exposed for testing only.
2229
@visibleForTesting
2330
FileSystem fs = LocalFileSystem();

packages/shared_preferences/shared_preferences_windows/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: shared_preferences_windows
22
description: Windows implementation of shared_preferences
33
homepage: https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences_windows
4-
version: 2.0.0
5-
4+
version: 2.0.1
65

76
flutter:
87
plugin:
8+
implements: shared_preferences
99
platforms:
1010
windows:
1111
dartPluginClass: SharedPreferencesWindows

packages/shared_preferences/shared_preferences_windows/test/shared_preferences_windows_test.dart

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
77
import 'package:path/path.dart' as path;
88
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
99
import 'package:path_provider_windows/path_provider_windows.dart';
10+
import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart';
1011
import 'package:shared_preferences_windows/shared_preferences_windows.dart';
1112

1213
void main() {
@@ -18,8 +19,6 @@ void main() {
1819
pathProvider = FakePathProviderWindows();
1920
});
2021

21-
tearDown(() {});
22-
2322
Future<String> _getFilePath() async {
2423
final directory = await pathProvider.getApplicationSupportPath();
2524
return path.join(directory!, 'shared_preferences.json');
@@ -42,6 +41,12 @@ void main() {
4241
return prefs;
4342
}
4443

44+
test('registered instance', () {
45+
SharedPreferencesWindows.registerWith();
46+
expect(SharedPreferencesStorePlatform.instance,
47+
isA<SharedPreferencesWindows>());
48+
});
49+
4550
test('getAll', () async {
4651
await _writeTestFile('{"key1": "one", "key2": 2}');
4752
var prefs = _getPreferences();

0 commit comments

Comments
 (0)