switch statement cleanup (#148382)

This PR is step 12 in the journey to solve issue #136139 and make the
entire Flutter repo more readable.

Most of it involves implementing switch expressions, and there's also a
few other random things that I wanted to clean up a bit.
This commit is contained in:
Nate
2024-05-16 18:16:06 -06:00
committed by GitHub
parent c4ad1dc1e9
commit fa9992eff6
39 changed files with 301 additions and 529 deletions

View File

@@ -353,16 +353,14 @@ class TestDefaultBinaryMessenger extends BinaryMessenger {
final StreamController<Object?> controller = StreamController<Object?>();
addTearDown(controller.close);
setMockMethodCallHandler(MethodChannel(channel.name, channel.codec), (MethodCall call) async {
switch (call.method) {
case 'listen':
return handler.onListen(call.arguments, MockStreamHandlerEventSink(controller.sink));
case 'cancel':
return handler.onCancel(call.arguments);
default:
throw UnimplementedError('Method ${call.method} not implemented');
}
});
setMockMethodCallHandler(
MethodChannel(channel.name, channel.codec),
(MethodCall call) async => switch (call.method) {
'listen' => handler.onListen(call.arguments, MockStreamHandlerEventSink(controller.sink)),
'cancel' => handler.onCancel(call.arguments),
_ => throw UnimplementedError('Method ${call.method} not implemented'),
},
);
final StreamSubscription<Object?> sub = controller.stream.listen(
(Object? e) => handlePlatformMessage(