From b7541dd49fedd9882375142848a9ed6930d25450 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Tue, 20 Jun 2023 12:35:35 -0400 Subject: [PATCH] Update `platform_channels` for 3.10 (#1902) Replaces deprecated APIs in unit tests. Fixes https://github.com/flutter/samples/issues/1765 ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] All existing and new tests are passing. [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/wiki/Chat [Contributors Guide]: https://github.com/flutter/samples/blob/main/CONTRIBUTING.md --- platform_channels/test/src/event_channel_demo_test.dart | 6 ++++-- platform_channels/test/src/pet_list_screen_test.dart | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/platform_channels/test/src/event_channel_demo_test.dart b/platform_channels/test/src/event_channel_demo_test.dart index 9b6732536..86b166a75 100644 --- a/platform_channels/test/src/event_channel_demo_test.dart +++ b/platform_channels/test/src/event_channel_demo_test.dart @@ -20,7 +20,8 @@ void main() { // and add the incoming message to the StreamController used by the EventChannel // after decoding the message with codec used by the EventChannel. void emitValues(ByteData? event) { - ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage( + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .handlePlatformMessage( 'eventChannelDemo', event, (reply) {}, @@ -29,7 +30,8 @@ void main() { // Register a mock for EventChannel. EventChannel under the hood uses // MethodChannel to listen and cancel the created stream. - ServicesBinding.instance.defaultBinaryMessenger + + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMessageHandler('eventChannelDemo', (message) async { // Decode the message into MethodCallHandler. final methodCall = standardMethod.decodeMethodCall(message); diff --git a/platform_channels/test/src/pet_list_screen_test.dart b/platform_channels/test/src/pet_list_screen_test.dart index 88d73b351..74fcfeae3 100644 --- a/platform_channels/test/src/pet_list_screen_test.dart +++ b/platform_channels/test/src/pet_list_screen_test.dart @@ -26,15 +26,18 @@ void main() { setUpAll(() { // Mock for the pet list received from the platform. - basicMessageChannel.setMockMessageHandler((message) async { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockDecodedMessageHandler(basicMessageChannel, (message) async { petListModel = PetListModel.fromJson(message!); return null; }); // Mock for the index received from the Dart to delete the pet details, // and send the updated pet list back to Dart. - const BasicMessageChannel('binaryCodecDemo', BinaryCodec()) - .setMockMessageHandler((message) async { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockDecodedMessageHandler( + const BasicMessageChannel( + 'binaryCodecDemo', BinaryCodec()), (message) async { // Convert the ByteData to String. final index = utf8.decoder.convert(message!.buffer .asUint8List(message.offsetInBytes, message.lengthInBytes));