mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
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. <!-- Links --> [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
This commit is contained in:
@@ -20,7 +20,8 @@ void main() {
|
|||||||
// and add the incoming message to the StreamController used by the EventChannel
|
// and add the incoming message to the StreamController used by the EventChannel
|
||||||
// after decoding the message with codec used by the EventChannel.
|
// after decoding the message with codec used by the EventChannel.
|
||||||
void emitValues(ByteData? event) {
|
void emitValues(ByteData? event) {
|
||||||
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||||
|
.handlePlatformMessage(
|
||||||
'eventChannelDemo',
|
'eventChannelDemo',
|
||||||
event,
|
event,
|
||||||
(reply) {},
|
(reply) {},
|
||||||
@@ -29,7 +30,8 @@ void main() {
|
|||||||
|
|
||||||
// Register a mock for EventChannel. EventChannel under the hood uses
|
// Register a mock for EventChannel. EventChannel under the hood uses
|
||||||
// MethodChannel to listen and cancel the created stream.
|
// MethodChannel to listen and cancel the created stream.
|
||||||
ServicesBinding.instance.defaultBinaryMessenger
|
|
||||||
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||||
.setMockMessageHandler('eventChannelDemo', (message) async {
|
.setMockMessageHandler('eventChannelDemo', (message) async {
|
||||||
// Decode the message into MethodCallHandler.
|
// Decode the message into MethodCallHandler.
|
||||||
final methodCall = standardMethod.decodeMethodCall(message);
|
final methodCall = standardMethod.decodeMethodCall(message);
|
||||||
|
|||||||
@@ -26,15 +26,18 @@ void main() {
|
|||||||
|
|
||||||
setUpAll(() {
|
setUpAll(() {
|
||||||
// Mock for the pet list received from the platform.
|
// Mock for the pet list received from the platform.
|
||||||
basicMessageChannel.setMockMessageHandler((message) async {
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||||
|
.setMockDecodedMessageHandler(basicMessageChannel, (message) async {
|
||||||
petListModel = PetListModel.fromJson(message!);
|
petListModel = PetListModel.fromJson(message!);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mock for the index received from the Dart to delete the pet details,
|
// Mock for the index received from the Dart to delete the pet details,
|
||||||
// and send the updated pet list back to Dart.
|
// and send the updated pet list back to Dart.
|
||||||
const BasicMessageChannel<ByteData?>('binaryCodecDemo', BinaryCodec())
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||||
.setMockMessageHandler((message) async {
|
.setMockDecodedMessageHandler(
|
||||||
|
const BasicMessageChannel<ByteData?>(
|
||||||
|
'binaryCodecDemo', BinaryCodec()), (message) async {
|
||||||
// Convert the ByteData to String.
|
// Convert the ByteData to String.
|
||||||
final index = utf8.decoder.convert(message!.buffer
|
final index = utf8.decoder.convert(message!.buffer
|
||||||
.asUint8List(message.offsetInBytes, message.lengthInBytes));
|
.asUint8List(message.offsetInBytes, message.lengthInBytes));
|
||||||
|
|||||||
Reference in New Issue
Block a user