Skip to content

Commit e08e149

Browse files
[various] Disambiguate TestDefaultBinaryMessengerBinding (flutter#6009)
Removes the "ambiguate" method that was used to allow compatibility with both stable and master during the transition of `TestDefaultBinaryMessengerBinding.instance` from a nullable return to a non-nullable return, now that all versions we analyze are sufficiently new to have the non-nullable version. Part of flutter#111841
1 parent 7c95a32 commit e08e149

File tree

30 files changed

+100
-339
lines changed

30 files changed

+100
-339
lines changed

packages/camera/camera_avfoundation/test/avfoundation_camera_test.dart

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ void main() {
3232
// registerWith is called very early in initialization the bindings won't
3333
// have been initialized. While registerWith could initialize them, that
3434
// could slow down startup, so instead the handler should be set up lazily.
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) {});
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) {});
4443
expect(response, null);
4544
});
4645

@@ -422,8 +421,7 @@ void main() {
422421
const DeviceOrientationChangedEvent event =
423422
DeviceOrientationChangedEvent(DeviceOrientation.portraitUp);
424423
for (int i = 0; i < 3; i++) {
425-
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
426-
.defaultBinaryMessenger
424+
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
427425
.handlePlatformMessage(
428426
AVFoundationCamera.deviceEventChannelName,
429427
const StandardMethodCodec().encodeMethodCall(
@@ -1187,9 +1185,3 @@ void main() {
11871185
});
11881186
});
11891187
}
1190-
1191-
/// This allows a value of type T or T? to be treated as a value of type T?.
1192-
///
1193-
/// We use this so that APIs that have become non-nullable can still be used
1194-
/// with `!` and `?` on the stable branch.
1195-
T? _ambiguate<T>(T? value) => value;

packages/camera/camera_avfoundation/test/method_channel_mock.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class MethodChannelMock {
1111
this.delay,
1212
required this.methods,
1313
}) : methodChannel = MethodChannel(channelName) {
14-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
15-
.defaultBinaryMessenger
14+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
1615
.setMockMethodCallHandler(methodChannel, _handler);
1716
}
1817

@@ -39,9 +38,3 @@ class MethodChannelMock {
3938
});
4039
}
4140
}
42-
43-
/// This allows a value of type T or T? to be treated as a value of type T?.
44-
///
45-
/// We use this so that APIs that have become non-nullable can still be used
46-
/// with `!` and `?` on the stable branch.
47-
T? _ambiguate<T>(T? value) => value;

packages/camera/camera_platform_interface/test/utils/method_channel_mock.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class MethodChannelMock {
1111
this.delay,
1212
required this.methods,
1313
}) : methodChannel = MethodChannel(channelName) {
14-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
15-
.defaultBinaryMessenger
14+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
1615
.setMockMethodCallHandler(methodChannel, _handler);
1716
}
1817

@@ -39,9 +38,3 @@ class MethodChannelMock {
3938
});
4039
}
4140
}
42-
43-
/// This allows a value of type T or T? to be treated as a value of type T?.
44-
///
45-
/// We use this so that APIs that have become non-nullable can still be used
46-
/// with `!` and `?` on the stable branch.
47-
T? _ambiguate<T>(T? value) => value;

packages/camera/camera_windows/test/utils/method_channel_mock.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class MethodChannelMock {
1717
this.delay,
1818
required this.methods,
1919
}) : methodChannel = MethodChannel(channelName) {
20-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
21-
.defaultBinaryMessenger
20+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
2221
.setMockMethodCallHandler(methodChannel, _handler);
2322
}
2423

@@ -45,9 +44,3 @@ class MethodChannelMock {
4544
});
4645
}
4746
}
48-
49-
/// This allows a value of type T or T? to be treated as a value of type T?.
50-
///
51-
/// We use this so that APIs that have become non-nullable can still be used
52-
/// with `!` and `?` on the stable branch.
53-
T? _ambiguate<T>(T? value) => value;

packages/file_selector/file_selector_linux/test/file_selector_linux_test.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ void main() {
1616
setUp(() {
1717
plugin = FileSelectorLinux();
1818
log = <MethodCall>[];
19-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
20-
.defaultBinaryMessenger
19+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
2120
.setMockMethodCallHandler(
2221
plugin.channel,
2322
(MethodCall methodCall) async {
@@ -527,9 +526,3 @@ void expectMethodCall(
527526
}) {
528527
expect(log, <Matcher>[isMethodCall(methodName, arguments: arguments)]);
529528
}
530-
531-
/// This allows a value of type T or T? to be treated as a value of type T?.
532-
///
533-
/// We use this so that APIs that have become non-nullable can still be used
534-
/// with `!` and `?` on the stable branch.
535-
T? _ambiguate<T>(T? value) => value;

packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ void main() {
1616
final List<MethodCall> log = <MethodCall>[];
1717

1818
setUp(() {
19-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
20-
.defaultBinaryMessenger
19+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
2120
.setMockMethodCallHandler(
2221
plugin.channel,
2322
(MethodCall methodCall) async {
@@ -279,9 +278,3 @@ void expectMethodCall(
279278
}) {
280279
expect(log, <Matcher>[isMethodCall(methodName, arguments: arguments)]);
281280
}
282-
283-
/// This allows a value of type T or T? to be treated as a value of type T?.
284-
///
285-
/// We use this so that APIs that have become non-nullable can still be used
286-
/// with `!` and `?` on the stable branch.
287-
T? _ambiguate<T>(T? value) => value;

packages/go_router/test/go_router_test.dart

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -774,8 +774,7 @@ void main() {
774774
'Handles the Android back button when parentNavigatorKey is set to the root navigator',
775775
(WidgetTester tester) async {
776776
final List<MethodCall> log = <MethodCall>[];
777-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
778-
.defaultBinaryMessenger
777+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
779778
.setMockMethodCallHandler(SystemChannels.platform,
780779
(MethodCall methodCall) async {
781780
log.add(methodCall);
@@ -817,8 +816,7 @@ void main() {
817816
testWidgets("Handles the Android back button when ShellRoute can't pop",
818817
(WidgetTester tester) async {
819818
final List<MethodCall> log = <MethodCall>[];
820-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
821-
.defaultBinaryMessenger
819+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
822820
.setMockMethodCallHandler(SystemChannels.platform,
823821
(MethodCall methodCall) async {
824822
log.add(methodCall);
@@ -917,8 +915,7 @@ void main() {
917915
'Handles the Android back button when a second Shell has a GoRoute with parentNavigator key',
918916
(WidgetTester tester) async {
919917
final List<MethodCall> log = <MethodCall>[];
920-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
921-
.defaultBinaryMessenger
918+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
922919
.setMockMethodCallHandler(SystemChannels.platform,
923920
(MethodCall methodCall) async {
924921
log.add(methodCall);
@@ -1008,8 +1005,7 @@ void main() {
10081005
final List<MethodCall> log = <MethodCall>[];
10091006
setUp(() {
10101007
GoRouter.optionURLReflectsImperativeAPIs = false;
1011-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
1012-
.defaultBinaryMessenger
1008+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
10131009
.setMockMethodCallHandler(SystemChannels.navigation,
10141010
(MethodCall methodCall) async {
10151011
log.add(methodCall);
@@ -1018,8 +1014,7 @@ void main() {
10181014
});
10191015
tearDown(() {
10201016
GoRouter.optionURLReflectsImperativeAPIs = false;
1021-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
1022-
.defaultBinaryMessenger
1017+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
10231018
.setMockMethodCallHandler(SystemChannels.navigation, null);
10241019
log.clear();
10251020
});
@@ -5158,9 +5153,3 @@ class IsRouteUpdateCall extends Matcher {
51585153
.addDescriptionOf(replace);
51595154
}
51605155
}
5161-
5162-
/// This allows a value of type T or T? to be treated as a value of type T?.
5163-
///
5164-
/// We use this so that APIs that have become non-nullable can still be used
5165-
/// with `!` and `?` on the stable branch.
5166-
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ void main() {
2727
required Future<dynamic>? Function(MethodCall call) handler,
2828
}) {
2929
final MethodChannel channel = maps.ensureChannelInitialized(mapId);
30-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
31-
.defaultBinaryMessenger
30+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
3231
.setMockMethodCallHandler(
3332
channel,
3433
(MethodCall methodCall) {
@@ -42,8 +41,7 @@ void main() {
4241
int mapId, String method, Map<dynamic, dynamic> data) async {
4342
final ByteData byteData =
4443
const StandardMethodCodec().encodeMethodCall(MethodCall(method, data));
45-
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
46-
.defaultBinaryMessenger
44+
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
4745
.handlePlatformMessage('plugins.flutter.dev/google_maps_android_$mapId',
4846
byteData, (ByteData? data) {});
4947
}
@@ -218,9 +216,3 @@ void main() {
218216
);
219217
});
220218
}
221-
222-
/// This allows a value of type T or T? to be treated as a value of type T?.
223-
///
224-
/// We use this so that APIs that have become non-nullable can still be used
225-
/// with `!` and `?` on the stable branch.
226-
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter_ios/test/google_maps_flutter_ios_test.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ void main() {
2727
required Future<dynamic>? Function(MethodCall call) handler,
2828
}) {
2929
final MethodChannel channel = maps.ensureChannelInitialized(mapId);
30-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
31-
.defaultBinaryMessenger
30+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
3231
.setMockMethodCallHandler(
3332
channel,
3433
(MethodCall methodCall) {
@@ -42,8 +41,7 @@ void main() {
4241
int mapId, String method, Map<dynamic, dynamic> data) async {
4342
final ByteData byteData =
4443
const StandardMethodCodec().encodeMethodCall(MethodCall(method, data));
45-
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
46-
.defaultBinaryMessenger
44+
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
4745
.handlePlatformMessage('plugins.flutter.dev/google_maps_ios_$mapId',
4846
byteData, (ByteData? data) {});
4947
}
@@ -179,9 +177,3 @@ void main() {
179177
);
180178
});
181179
}
182-
183-
/// This allows a value of type T or T? to be treated as a value of type T?.
184-
///
185-
/// We use this so that APIs that have become non-nullable can still be used
186-
/// with `!` and `?` on the stable branch.
187-
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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ void main() {
2525
required Future<dynamic>? Function(MethodCall call) handler,
2626
}) {
2727
final MethodChannel channel = maps.ensureChannelInitialized(mapId);
28-
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
29-
.defaultBinaryMessenger
28+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
3029
.setMockMethodCallHandler(
3130
channel,
3231
(MethodCall methodCall) {
@@ -40,8 +39,7 @@ void main() {
4039
int mapId, String method, Map<dynamic, dynamic> data) async {
4140
final ByteData byteData = const StandardMethodCodec()
4241
.encodeMethodCall(MethodCall(method, data));
43-
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
44-
.defaultBinaryMessenger
42+
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
4543
.handlePlatformMessage('plugins.flutter.io/google_maps_$mapId',
4644
byteData, (ByteData? data) {});
4745
}
@@ -125,9 +123,3 @@ void main() {
125123
});
126124
});
127125
}
128-
129-
/// This allows a value of type T or T? to be treated as a value of type T?.
130-
///
131-
/// We use this so that APIs that have become non-nullable can still be used
132-
/// with `!` and `?` on the stable branch.
133-
T? _ambiguate<T>(T? value) => value;

0 commit comments

Comments
 (0)