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

Commit 05659f0

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 6dd1c46 commit 05659f0

File tree

9 files changed

+114
-41
lines changed

9 files changed

+114
-41
lines changed

packages/battery/battery_platform_interface/test/method_channel_battery_test.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ void main() {
3232
.setMockMethodCallHandler((MethodCall methodCall) async {
3333
switch (methodCall.method) {
3434
case 'listen':
35-
await ServicesBinding.instance!.defaultBinaryMessenger
35+
await _ambiguate(ServicesBinding.instance)!
36+
.defaultBinaryMessenger
3637
.handlePlatformMessage(
37-
methodChannelBattery.eventChannel.name,
38-
methodChannelBattery.eventChannel.codec
39-
.encodeSuccessEnvelope('full'),
40-
(_) {},
41-
);
38+
methodChannelBattery.eventChannel.name,
39+
methodChannelBattery.eventChannel.codec
40+
.encodeSuccessEnvelope('full'),
41+
(_) {},
42+
);
4243
break;
4344
case 'cancel':
4445
default:
@@ -61,3 +62,10 @@ void main() {
6162
});
6263
});
6364
}
65+
66+
/// This allows a value of type T or T? to be treated as a value of type T?.
67+
///
68+
/// We use this so that APIs that have become non-nullable can still be used
69+
/// with `!` and `?` on the stable branch.
70+
// TODO(ianh): Remove this once we roll stable in late 2021.
71+
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: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ void main() {
4242
.setMockMethodCallHandler((MethodCall methodCall) async {
4343
switch (methodCall.method) {
4444
case 'listen':
45-
await ServicesBinding.instance!.defaultBinaryMessenger
45+
await _ambiguate(ServicesBinding.instance)!
46+
.defaultBinaryMessenger
4647
.handlePlatformMessage(
47-
methodChannelConnectivity.eventChannel.name,
48-
methodChannelConnectivity.eventChannel.codec
49-
.encodeSuccessEnvelope('wifi'),
50-
(_) {},
51-
);
48+
methodChannelConnectivity.eventChannel.name,
49+
methodChannelConnectivity.eventChannel.codec
50+
.encodeSuccessEnvelope('wifi'),
51+
(_) {},
52+
);
5253
break;
5354
case 'cancel':
5455
default:
@@ -151,3 +152,10 @@ void main() {
151152
});
152153
});
153154
}
155+
156+
/// This allows a value of type T or T? to be treated as a value of type T?.
157+
///
158+
/// We use this so that APIs that have become non-nullable can still be used
159+
/// with `!` and `?` on the stable branch.
160+
// TODO(ianh): Remove this once we roll stable in late 2021.
161+
T? _ambiguate<T>(T? value) => value;

packages/sensors/test/sensors_test.dart

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

5454
void _emitEvent(ByteData? event) {
55-
ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage(
56-
channelName,
57-
event,
58-
(ByteData? reply) {},
59-
);
55+
_ambiguate(ServicesBinding.instance)!
56+
.defaultBinaryMessenger
57+
.handlePlatformMessage(
58+
channelName,
59+
event,
60+
(ByteData? reply) {},
61+
);
6062
}
6163

62-
ServicesBinding.instance!.defaultBinaryMessenger
64+
_ambiguate(ServicesBinding.instance)!
65+
.defaultBinaryMessenger
6366
.setMockMessageHandler(channelName, (ByteData? message) async {
6467
final MethodCall methodCall = standardMethod.decodeMethodCall(message);
6568
if (methodCall.method == 'listen') {
@@ -73,3 +76,10 @@ void _initializeFakeSensorChannel(String channelName, List<double> sensorData) {
7376
}
7477
});
7578
}
79+
80+
/// This allows a value of type T or T? to be treated as a value of type T?.
81+
///
82+
/// We use this so that APIs that have become non-nullable can still be used
83+
/// with `!` and `?` on the stable branch.
84+
// TODO(ianh): Remove this once we roll stable in late 2021.
85+
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.9
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.8
27

38
* Refactor `FLTCMTimeToMillis` to support indefinite streams. Fixes [#48670](https://github.com/flutter/flutter/issues/48670).

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.8
6+
version: 2.1.9
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: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,16 @@ void main() {
232232
});
233233

234234
test('videoEventsFor', () async {
235-
ServicesBinding.instance?.defaultBinaryMessenger.setMockMessageHandler(
235+
_ambiguate(ServicesBinding.instance)
236+
?.defaultBinaryMessenger
237+
.setMockMessageHandler(
236238
"flutter.io/videoPlayer/videoEvents123",
237239
(ByteData? message) async {
238240
final MethodCall methodCall =
239241
const StandardMethodCodec().decodeMethodCall(message);
240242
if (methodCall.method == 'listen') {
241-
await ServicesBinding.instance?.defaultBinaryMessenger
243+
await _ambiguate(ServicesBinding.instance)
244+
?.defaultBinaryMessenger
242245
.handlePlatformMessage(
243246
"flutter.io/videoPlayer/videoEvents123",
244247
const StandardMethodCodec()
@@ -250,7 +253,8 @@ void main() {
250253
}),
251254
(ByteData? data) {});
252255

253-
await ServicesBinding.instance?.defaultBinaryMessenger
256+
await _ambiguate(ServicesBinding.instance)
257+
?.defaultBinaryMessenger
254258
.handlePlatformMessage(
255259
"flutter.io/videoPlayer/videoEvents123",
256260
const StandardMethodCodec()
@@ -259,7 +263,8 @@ void main() {
259263
}),
260264
(ByteData? data) {});
261265

262-
await ServicesBinding.instance?.defaultBinaryMessenger
266+
await _ambiguate(ServicesBinding.instance)
267+
?.defaultBinaryMessenger
263268
.handlePlatformMessage(
264269
"flutter.io/videoPlayer/videoEvents123",
265270
const StandardMethodCodec()
@@ -272,7 +277,8 @@ void main() {
272277
}),
273278
(ByteData? data) {});
274279

275-
await ServicesBinding.instance?.defaultBinaryMessenger
280+
await _ambiguate(ServicesBinding.instance)
281+
?.defaultBinaryMessenger
276282
.handlePlatformMessage(
277283
"flutter.io/videoPlayer/videoEvents123",
278284
const StandardMethodCodec()
@@ -281,7 +287,8 @@ void main() {
281287
}),
282288
(ByteData? data) {});
283289

284-
await ServicesBinding.instance?.defaultBinaryMessenger
290+
await _ambiguate(ServicesBinding.instance)
291+
?.defaultBinaryMessenger
285292
.handlePlatformMessage(
286293
"flutter.io/videoPlayer/videoEvents123",
287294
const StandardMethodCodec()
@@ -325,3 +332,10 @@ void main() {
325332
});
326333
});
327334
}
335+
336+
/// This allows a value of type T or T? to be treated as a value of type T?.
337+
///
338+
/// We use this so that APIs that have become non-nullable can still be used
339+
/// with `!` and `?` on the stable branch.
340+
// TODO(ianh): Remove this once we roll stable in late 2021.
341+
T? _ambiguate<T>(T? value) => value;

packages/webview_flutter/test/webview_flutter_test.dart

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

@@ -1038,7 +1039,8 @@ class FakePlatformWebView {
10381039
};
10391040
final ByteData data =
10401041
codec.encodeMethodCall(MethodCall('navigationRequest', arguments));
1041-
ServicesBinding.instance!.defaultBinaryMessenger
1042+
_ambiguate(ServicesBinding.instance)!
1043+
.defaultBinaryMessenger
10421044
.handlePlatformMessage(channel.name, data, (ByteData? data) {
10431045
final bool allow = codec.decodeEnvelope(data!);
10441046
if (allow) {
@@ -1055,11 +1057,13 @@ class FakePlatformWebView {
10551057
<dynamic, dynamic>{'url': currentUrl},
10561058
));
10571059

1058-
ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage(
1059-
channel.name,
1060-
data,
1061-
(ByteData? data) {},
1062-
);
1060+
_ambiguate(ServicesBinding.instance)!
1061+
.defaultBinaryMessenger
1062+
.handlePlatformMessage(
1063+
channel.name,
1064+
data,
1065+
(ByteData? data) {},
1066+
);
10631067
}
10641068

10651069
void fakeOnPageFinishedCallback() {
@@ -1070,11 +1074,13 @@ class FakePlatformWebView {
10701074
<dynamic, dynamic>{'url': currentUrl},
10711075
));
10721076

1073-
ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage(
1074-
channel.name,
1075-
data,
1076-
(ByteData? data) {},
1077-
);
1077+
_ambiguate(ServicesBinding.instance)!
1078+
.defaultBinaryMessenger
1079+
.handlePlatformMessage(
1080+
channel.name,
1081+
data,
1082+
(ByteData? data) {},
1083+
);
10781084
}
10791085

10801086
void fakeOnProgressCallback(int progress) {
@@ -1085,7 +1091,8 @@ class FakePlatformWebView {
10851091
<dynamic, dynamic>{'progress': progress},
10861092
));
10871093

1088-
ServicesBinding.instance!.defaultBinaryMessenger
1094+
_ambiguate(ServicesBinding.instance)!
1095+
.defaultBinaryMessenger
10891096
.handlePlatformMessage(channel.name, data, (ByteData? data) {});
10901097
}
10911098

@@ -1244,3 +1251,10 @@ class MatchesCreationParams extends Matcher {
12441251
.matches(creationParams.javascriptChannelNames, matchState);
12451252
}
12461253
}
1254+
1255+
/// This allows a value of type T or T? to be treated as a value of type T?.
1256+
///
1257+
/// We use this so that APIs that have become non-nullable can still be used
1258+
/// with `!` and `?` on the stable branch.
1259+
// TODO(ianh): Remove this once we roll stable in late 2021.
1260+
T? _ambiguate<T>(T? value) => value;

0 commit comments

Comments
 (0)