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

Commit 562e45d

Browse files
committed
[various] Prepare plugin repo for binding API improvements
Since plugins also have to work with the stable branch, we can't actually take advantage of the changes right away, so we muddle the issue in the meantime. Prep for flutter/flutter#83843 See also #4136
1 parent 971d6c3 commit 562e45d

File tree

9 files changed

+73
-19
lines changed

9 files changed

+73
-19
lines changed

packages/battery/battery_platform_interface/test/method_channel_battery_test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void main() {
3232
.setMockMethodCallHandler((MethodCall methodCall) async {
3333
switch (methodCall.method) {
3434
case 'listen':
35-
await ServicesBinding.instance!.defaultBinaryMessenger
35+
await _ambiguate(ServicesBinding.instance)!.defaultBinaryMessenger
3636
.handlePlatformMessage(
3737
methodChannelBattery.eventChannel.name,
3838
methodChannelBattery.eventChannel.codec
@@ -61,3 +61,10 @@ void main() {
6161
});
6262
});
6363
}
64+
65+
/// This allows a value of type T or T? to be treated as a value of type T?.
66+
///
67+
/// We use this so that APIs that have become non-nullable can still be used
68+
/// with `!` and `?` on the stable branch.
69+
// TODO(ianh): Remove this once we roll stable in late 2021.
70+
T? _ambiguate<T>(T? value) => value;

packages/camera/camera/example/lib/main.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
6868
@override
6969
void initState() {
7070
super.initState();
71-
WidgetsBinding.instance?.addObserver(this);
71+
_ambiguate(WidgetsBinding.instance)?.addObserver(this);
7272

7373
_flashModeControlRowAnimationController = AnimationController(
7474
duration: const Duration(milliseconds: 300),
@@ -951,3 +951,10 @@ Future<void> main() async {
951951
}
952952
runApp(CameraApp());
953953
}
954+
955+
/// This allows a value of type T or T? to be treated as a value of type T?.
956+
///
957+
/// We use this so that APIs that have become non-nullable can still be used
958+
/// with `!` and `?` on the stable branch.
959+
// TODO(ianh): Remove this once we roll stable in late 2021.
960+
T? _ambiguate<T>(T? value) => value;

packages/connectivity/connectivity_platform_interface/test/method_channel_connectivity_test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void main() {
4242
.setMockMethodCallHandler((MethodCall methodCall) async {
4343
switch (methodCall.method) {
4444
case 'listen':
45-
await ServicesBinding.instance!.defaultBinaryMessenger
45+
await _ambiguate(ServicesBinding.instance)!.defaultBinaryMessenger
4646
.handlePlatformMessage(
4747
methodChannelConnectivity.eventChannel.name,
4848
methodChannelConnectivity.eventChannel.codec
@@ -151,3 +151,10 @@ void main() {
151151
});
152152
});
153153
}
154+
155+
/// This allows a value of type T or T? to be treated as a value of type T?.
156+
///
157+
/// We use this so that APIs that have become non-nullable can still be used
158+
/// with `!` and `?` on the stable branch.
159+
// TODO(ianh): Remove this once we roll stable in late 2021.
160+
T? _ambiguate<T>(T? value) => value;

packages/sensors/test/sensors_test.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ void _initializeFakeSensorChannel(String channelName, List<double> sensorData) {
5252
const StandardMethodCodec standardMethod = StandardMethodCodec();
5353

5454
void _emitEvent(ByteData? event) {
55-
ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage(
55+
_ambiguate(ServicesBinding.instance)!.defaultBinaryMessenger.handlePlatformMessage(
5656
channelName,
5757
event,
5858
(ByteData? reply) {},
5959
);
6060
}
6161

62-
ServicesBinding.instance!.defaultBinaryMessenger
62+
_ambiguate(ServicesBinding.instance)!.defaultBinaryMessenger
6363
.setMockMessageHandler(channelName, (ByteData? message) async {
6464
final MethodCall methodCall = standardMethod.decodeMethodCall(message);
6565
if (methodCall.method == 'listen') {
@@ -73,3 +73,10 @@ void _initializeFakeSensorChannel(String channelName, List<double> sensorData) {
7373
}
7474
});
7575
}
76+
77+
/// This allows a value of type T or T? to be treated as a value of type T?.
78+
///
79+
/// We use this so that APIs that have become non-nullable can still be used
80+
/// with `!` and `?` on the stable branch.
81+
// TODO(ianh): Remove this once we roll stable in late 2021.
82+
T? _ambiguate<T>(T? value) => value;

packages/video_player/video_player/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.1.7
2+
3+
* Silenced warnings that may occur during build when using a very
4+
recent version of Flutter relating to null safety.
5+
16
## 2.1.6
27

38
* Remove obsolete pre-1.0 warning from README.

packages/video_player/video_player/lib/video_player.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ class _VideoAppLifeCycleObserver extends Object with WidgetsBindingObserver {
573573
final VideoPlayerController _controller;
574574

575575
void initialize() {
576-
WidgetsBinding.instance!.addObserver(this);
576+
_ambiguate(WidgetsBinding.instance)!.addObserver(this);
577577
}
578578

579579
@override
@@ -593,7 +593,7 @@ class _VideoAppLifeCycleObserver extends Object with WidgetsBindingObserver {
593593
}
594594

595595
void dispose() {
596-
WidgetsBinding.instance!.removeObserver(this);
596+
_ambiguate(WidgetsBinding.instance)!.removeObserver(this);
597597
}
598598
}
599599

@@ -949,3 +949,10 @@ class ClosedCaption extends StatelessWidget {
949949
);
950950
}
951951
}
952+
953+
/// This allows a value of type T or T? to be treated as a value of type T?.
954+
///
955+
/// We use this so that APIs that have become non-nullable can still be used
956+
/// with `!` and `?` on the stable branch.
957+
// TODO(ianh): Remove this once we roll stable in late 2021.
958+
T? _ambiguate<T>(T? value) => value;

packages/video_player/video_player/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
33
widgets on Android, iOS, and web.
44
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
6-
version: 2.1.6
6+
version: 2.1.7
77

88
environment:
99
sdk: ">=2.12.0 <3.0.0"

packages/video_player/video_player_platform_interface/test/method_channel_video_player_test.dart

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ void main() {
232232
});
233233

234234
test('videoEventsFor', () async {
235-
ServicesBinding.instance?.defaultBinaryMessenger.setMockMessageHandler(
235+
_ambiguate(ServicesBinding.instance)?.defaultBinaryMessenger.setMockMessageHandler(
236236
"flutter.io/videoPlayer/videoEvents123",
237237
(ByteData? message) async {
238238
final MethodCall methodCall =
239239
const StandardMethodCodec().decodeMethodCall(message);
240240
if (methodCall.method == 'listen') {
241-
await ServicesBinding.instance?.defaultBinaryMessenger
241+
await _ambiguate(ServicesBinding.instance)?.defaultBinaryMessenger
242242
.handlePlatformMessage(
243243
"flutter.io/videoPlayer/videoEvents123",
244244
const StandardMethodCodec()
@@ -250,7 +250,7 @@ void main() {
250250
}),
251251
(ByteData? data) {});
252252

253-
await ServicesBinding.instance?.defaultBinaryMessenger
253+
await _ambiguate(ServicesBinding.instance)?.defaultBinaryMessenger
254254
.handlePlatformMessage(
255255
"flutter.io/videoPlayer/videoEvents123",
256256
const StandardMethodCodec()
@@ -259,7 +259,7 @@ void main() {
259259
}),
260260
(ByteData? data) {});
261261

262-
await ServicesBinding.instance?.defaultBinaryMessenger
262+
await _ambiguate(ServicesBinding.instance)?.defaultBinaryMessenger
263263
.handlePlatformMessage(
264264
"flutter.io/videoPlayer/videoEvents123",
265265
const StandardMethodCodec()
@@ -272,7 +272,7 @@ void main() {
272272
}),
273273
(ByteData? data) {});
274274

275-
await ServicesBinding.instance?.defaultBinaryMessenger
275+
await _ambiguate(ServicesBinding.instance)?.defaultBinaryMessenger
276276
.handlePlatformMessage(
277277
"flutter.io/videoPlayer/videoEvents123",
278278
const StandardMethodCodec()
@@ -281,7 +281,7 @@ void main() {
281281
}),
282282
(ByteData? data) {});
283283

284-
await ServicesBinding.instance?.defaultBinaryMessenger
284+
await _ambiguate(ServicesBinding.instance)?.defaultBinaryMessenger
285285
.handlePlatformMessage(
286286
"flutter.io/videoPlayer/videoEvents123",
287287
const StandardMethodCodec()
@@ -325,3 +325,10 @@ void main() {
325325
});
326326
});
327327
}
328+
329+
/// This allows a value of type T or T? to be treated as a value of type T?.
330+
///
331+
/// We use this so that APIs that have become non-nullable can still be used
332+
/// with `!` and `?` on the stable branch.
333+
// TODO(ianh): Remove this once we roll stable in late 2021.
334+
T? _ambiguate<T>(T? value) => value;

packages/webview_flutter/test/webview_flutter_test.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ class FakePlatformWebView {
10191019
};
10201020
final ByteData data = codec
10211021
.encodeMethodCall(MethodCall('javascriptChannelMessage', arguments));
1022-
ServicesBinding.instance!.defaultBinaryMessenger
1022+
_ambiguate(ServicesBinding.instance)!.defaultBinaryMessenger
10231023
.handlePlatformMessage(channel.name, data, (ByteData? data) {});
10241024
}
10251025

@@ -1038,7 +1038,7 @@ class FakePlatformWebView {
10381038
};
10391039
final ByteData data =
10401040
codec.encodeMethodCall(MethodCall('navigationRequest', arguments));
1041-
ServicesBinding.instance!.defaultBinaryMessenger
1041+
_ambiguate(ServicesBinding.instance)!.defaultBinaryMessenger
10421042
.handlePlatformMessage(channel.name, data, (ByteData? data) {
10431043
final bool allow = codec.decodeEnvelope(data!);
10441044
if (allow) {
@@ -1055,7 +1055,7 @@ class FakePlatformWebView {
10551055
<dynamic, dynamic>{'url': currentUrl},
10561056
));
10571057

1058-
ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage(
1058+
_ambiguate(ServicesBinding.instance)!.defaultBinaryMessenger.handlePlatformMessage(
10591059
channel.name,
10601060
data,
10611061
(ByteData? data) {},
@@ -1070,7 +1070,7 @@ class FakePlatformWebView {
10701070
<dynamic, dynamic>{'url': currentUrl},
10711071
));
10721072

1073-
ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage(
1073+
_ambiguate(ServicesBinding.instance)!.defaultBinaryMessenger.handlePlatformMessage(
10741074
channel.name,
10751075
data,
10761076
(ByteData? data) {},
@@ -1085,7 +1085,7 @@ class FakePlatformWebView {
10851085
<dynamic, dynamic>{'progress': progress},
10861086
));
10871087

1088-
ServicesBinding.instance!.defaultBinaryMessenger
1088+
_ambiguate(ServicesBinding.instance)!.defaultBinaryMessenger
10891089
.handlePlatformMessage(channel.name, data, (ByteData? data) {});
10901090
}
10911091

@@ -1244,3 +1244,10 @@ class MatchesCreationParams extends Matcher {
12441244
.matches(creationParams.javascriptChannelNames, matchState);
12451245
}
12461246
}
1247+
1248+
/// This allows a value of type T or T? to be treated as a value of type T?.
1249+
///
1250+
/// We use this so that APIs that have become non-nullable can still be used
1251+
/// with `!` and `?` on the stable branch.
1252+
// TODO(ianh): Remove this once we roll stable in late 2021.
1253+
T? _ambiguate<T>(T? value) => value;

0 commit comments

Comments
 (0)