@@ -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;
0 commit comments