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

Commit d5bab16

Browse files
authored
prepare for TestDefaultBinaryMessengerBinding.instance becoming non-nullable (#6847)
1 parent 4cf6f44 commit d5bab16

File tree

13 files changed

+58
-30
lines changed

13 files changed

+58
-30
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -1091,5 +1091,4 @@ Future<void> main() async {
10911091
///
10921092
/// We use this so that APIs that have become non-nullable can still be used
10931093
/// with `!` and `?` on the stable branch.
1094-
// TODO(ianh): Remove this once we roll stable in late 2021.
10951094
T? _ambiguate<T>(T? value) => value;

packages/camera/camera_android/test/android_camera_test.dart

+17-9
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ void main() {
3232
// registerWith is called very early in initialization the bindings won't
3333
// have been initialized. While registerWith could intialize them, that
3434
// could slow down startup, so instead the handler should be set up lazily.
35-
final ByteData? response = await TestDefaultBinaryMessengerBinding
36-
.instance!.defaultBinaryMessenger
37-
.handlePlatformMessage(
38-
AndroidCamera.deviceEventChannelName,
39-
const StandardMethodCodec().encodeMethodCall(const MethodCall(
40-
'orientation_changed',
41-
<String, Object>{'orientation': 'portraitDown'})),
42-
(ByteData? data) {});
35+
final ByteData? response =
36+
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
37+
.defaultBinaryMessenger
38+
.handlePlatformMessage(
39+
AndroidCamera.deviceEventChannelName,
40+
const StandardMethodCodec().encodeMethodCall(const MethodCall(
41+
'orientation_changed',
42+
<String, Object>{'orientation': 'portraitDown'})),
43+
(ByteData? data) {});
4344
expect(response, null);
4445
});
4546

@@ -421,7 +422,8 @@ void main() {
421422
const DeviceOrientationChangedEvent event =
422423
DeviceOrientationChangedEvent(DeviceOrientation.portraitUp);
423424
for (int i = 0; i < 3; i++) {
424-
await TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger
425+
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
426+
.defaultBinaryMessenger
425427
.handlePlatformMessage(
426428
AndroidCamera.deviceEventChannelName,
427429
const StandardMethodCodec().encodeMethodCall(
@@ -1121,3 +1123,9 @@ void main() {
11211123
});
11221124
});
11231125
}
1126+
1127+
/// This allows a value of type T or T? to be treated as a value of type T?.
1128+
///
1129+
/// We use this so that APIs that have become non-nullable can still be used
1130+
/// with `!` and `?` on the stable branch.
1131+
T? _ambiguate<T>(T? value) => value;

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

-1
Original file line numberDiff line numberDiff line change
@@ -1091,5 +1091,4 @@ Future<void> main() async {
10911091
///
10921092
/// We use this so that APIs that have become non-nullable can still be used
10931093
/// with `!` and `?` on the stable branch.
1094-
// TODO(ianh): Remove this once we roll stable in late 2021.
10951094
T? _ambiguate<T>(T? value) => value;

packages/camera/camera_avfoundation/test/avfoundation_camera_test.dart

+17-9
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ void main() {
3232
// registerWith is called very early in initialization the bindings won't
3333
// have been initialized. While registerWith could intialize them, that
3434
// could slow down startup, so instead the handler should be set up lazily.
35-
final ByteData? response = await TestDefaultBinaryMessengerBinding
36-
.instance!.defaultBinaryMessenger
37-
.handlePlatformMessage(
38-
AVFoundationCamera.deviceEventChannelName,
39-
const StandardMethodCodec().encodeMethodCall(const MethodCall(
40-
'orientation_changed',
41-
<String, Object>{'orientation': 'portraitDown'})),
42-
(ByteData? data) {});
35+
final ByteData? response =
36+
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
37+
.defaultBinaryMessenger
38+
.handlePlatformMessage(
39+
AVFoundationCamera.deviceEventChannelName,
40+
const StandardMethodCodec().encodeMethodCall(const MethodCall(
41+
'orientation_changed',
42+
<String, Object>{'orientation': 'portraitDown'})),
43+
(ByteData? data) {});
4344
expect(response, null);
4445
});
4546

@@ -421,7 +422,8 @@ void main() {
421422
const DeviceOrientationChangedEvent event =
422423
DeviceOrientationChangedEvent(DeviceOrientation.portraitUp);
423424
for (int i = 0; i < 3; i++) {
424-
await TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger
425+
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
426+
.defaultBinaryMessenger
425427
.handlePlatformMessage(
426428
AVFoundationCamera.deviceEventChannelName,
427429
const StandardMethodCodec().encodeMethodCall(
@@ -1122,3 +1124,9 @@ void main() {
11221124
});
11231125
});
11241126
}
1127+
1128+
/// This allows a value of type T or T? to be treated as a value of type T?.
1129+
///
1130+
/// We use this so that APIs that have become non-nullable can still be used
1131+
/// with `!` and `?` on the stable branch.
1132+
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ void main() {
3737
int mapId, String method, Map<dynamic, dynamic> data) async {
3838
final ByteData byteData =
3939
const StandardMethodCodec().encodeMethodCall(MethodCall(method, data));
40-
await TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger
40+
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
41+
.defaultBinaryMessenger
4142
.handlePlatformMessage('plugins.flutter.dev/google_maps_android_$mapId',
4243
byteData, (ByteData? data) {});
4344
}
@@ -164,3 +165,9 @@ void main() {
164165
expect(widget, isA<PlatformViewLink>());
165166
});
166167
}
168+
169+
/// This allows a value of type T or T? to be treated as a value of type T?.
170+
///
171+
/// We use this so that APIs that have become non-nullable can still be used
172+
/// with `!` and `?` on the stable branch.
173+
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter_ios/test/google_maps_flutter_ios_test.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ void main() {
3636
int mapId, String method, Map<dynamic, dynamic> data) async {
3737
final ByteData byteData =
3838
const StandardMethodCodec().encodeMethodCall(MethodCall(method, data));
39-
await TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger
39+
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
40+
.defaultBinaryMessenger
4041
.handlePlatformMessage('plugins.flutter.dev/google_maps_ios_$mapId',
4142
byteData, (ByteData? data) {});
4243
}
@@ -122,3 +123,9 @@ void main() {
122123
equals('drag-end-marker'));
123124
});
124125
}
126+
127+
/// This allows a value of type T or T? to be treated as a value of type T?.
128+
///
129+
/// We use this so that APIs that have become non-nullable can still be used
130+
/// with `!` and `?` on the stable branch.
131+
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter_platform_interface/test/method_channel/method_channel_google_maps_flutter_test.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ void main() {
3636
int mapId, String method, Map<dynamic, dynamic> data) async {
3737
final ByteData byteData = const StandardMethodCodec()
3838
.encodeMethodCall(MethodCall(method, data));
39-
await TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger
39+
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
40+
.defaultBinaryMessenger
4041
.handlePlatformMessage('plugins.flutter.io/google_maps_$mapId',
4142
byteData, (ByteData? data) {});
4243
}
@@ -120,3 +121,9 @@ void main() {
120121
});
121122
});
122123
}
124+
125+
/// This allows a value of type T or T? to be treated as a value of type T?.
126+
///
127+
/// We use this so that APIs that have become non-nullable can still be used
128+
/// with `!` and `?` on the stable branch.
129+
T? _ambiguate<T>(T? value) => value;

packages/url_launcher/url_launcher/lib/src/legacy_api.dart

-1
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,4 @@ Future<void> closeWebView() async {
150150
///
151151
/// We use this so that APIs that have become non-nullable can still be used
152152
/// with `!` and `?` on the stable branch.
153-
// TODO(ianh): Remove this once we roll stable in late 2021.
154153
T? _ambiguate<T>(T? value) => value;

packages/url_launcher/url_launcher/test/src/legacy_api_test.dart

-2
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,6 @@ void main() {
321321

322322
/// This removes the type information from a value so that it can be cast
323323
/// to another type even if that cast is redundant.
324-
///
325324
/// We use this so that APIs whose type have become more descriptive can still
326325
/// be used on the stable branch where they require a cast.
327-
// TODO(ianh): Remove this once we roll stable in late 2021.
328326
Object? _anonymize<T>(T? value) => value;

packages/url_launcher/url_launcher_platform_interface/lib/link.dart

-1
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,4 @@ Future<ByteData> pushRouteNameToFramework(Object? _, String routeName) {
109109
///
110110
/// We use this so that APIs that have become non-nullable can still be used
111111
/// with `!` and `?` on the stable branch.
112-
// TODO(ianh): Remove this once we roll stable in late 2021.
113112
T? _ambiguate<T>(T? value) => value;

packages/video_player/video_player/lib/video_player.dart

-1
Original file line numberDiff line numberDiff line change
@@ -1100,5 +1100,4 @@ class ClosedCaption extends StatelessWidget {
11001100
///
11011101
/// We use this so that APIs that have become non-nullable can still be used
11021102
/// with `!` and `?` on the stable branch.
1103-
// TODO(ianh): Remove this once we roll stable in late 2021.
11041103
T? _ambiguate<T>(T? value) => value;

packages/video_player/video_player_android/test/android_video_player_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -360,5 +360,4 @@ void main() {
360360
///
361361
/// We use this so that APIs that have become non-nullable can still be used
362362
/// with `!` and `?` on the stable branch.
363-
// TODO(ianh): Remove this once we roll stable in late 2021.
364363
T? _ambiguate<T>(T? value) => value;

packages/video_player/video_player_avfoundation/test/avfoundation_video_player_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -339,5 +339,4 @@ void main() {
339339
///
340340
/// We use this so that APIs that have become non-nullable can still be used
341341
/// with `!` and `?` on the stable branch.
342-
// TODO(ianh): Remove this once we roll stable in late 2021.
343342
T? _ambiguate<T>(T? value) => value;

0 commit comments

Comments
 (0)