TestDefaultBinaryMessenger class
A BinaryMessenger subclass that is used as the default binary messenger under testing environment.
It tracks status of data sent across the Flutter platform barrier, which is useful for testing frameworks to monitor and synchronize against the platform messages.
Messages from the framework to the platform
Messages are sent from the framework to the platform via the send method.
To intercept a message sent from the framework to the platform, consider using setMockMessageHandler, setMockDecodedMessageHandler, and setMockMethodCallHandler (see also checkMockMessageHandler).
To wait for all pending framework-to-platform messages, the platformMessagesFinished getter provides an appropriate Future. The pendingMessageCount getter returns the current number of outstanding messages.
Messages from the platform to the framework
The platform sends messages via the ChannelBuffers API. Mock messages can be sent to the framework using handlePlatformMessage.
Listeners for these messages are configured using setMessageHandler.
- Inheritance
-
- Object
- BinaryMessenger
- TestDefaultBinaryMessenger
- Available extensions
Constructors
-
TestDefaultBinaryMessenger(BinaryMessenger delegate, {Map<
String, MessageHandler> outboundHandlers = const <String, MessageHandler>{}}) - Creates a TestDefaultBinaryMessenger instance.
Properties
- allMessagesHandler ↔ AllMessagesHandler?
-
Handler that intercepts and responds to outgoing messages, pretending
to be the platform, for all channels.
getter/setter pair
- delegate → BinaryMessenger
-
The delegate BinaryMessenger.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- pendingMessageCount → int
-
The number of incomplete/pending calls sent to the platform channels.
no setter
-
platformMessagesFinished
→ Future<
void> -
Returns a Future that completes after all the platform calls are finished.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
checkMockMessageHandler(
String channel, Object? handler) → bool -
Returns true if the
handler
argument matches thehandler
previously passed to setMockMessageHandler, setMockDecodedMessageHandler, or setMockMethodCallHandler. -
checkMockMessageHandler(
String channel, Object? handler) → bool -
Available on BinaryMessenger, provided by the TestBinaryMessengerExtension extension
Shim for TestDefaultBinaryMessenger.checkMockMessageHandler. -
handlePlatformMessage(
String channel, ByteData? data, PlatformMessageResponseCallback? callback) → Future< ByteData?> -
Send a mock message to the framework as if it came from the platform.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
send(
String channel, ByteData? message) → Future< ByteData?> ? -
Send a binary message to the platform plugins on the given channel.
override
-
setMessageHandler(
String channel, MessageHandler? handler) → void -
Set a callback for receiving messages from the platform plugins on the
given channel, without decoding them.
override
-
setMockDecodedMessageHandler<
T> (BasicMessageChannel< T> channel, Future<T> handler(T? message)?) → void - Set a callback for intercepting messages sent to the platform on the given channel.
-
setMockMessageHandler(
String channel, MessageHandler? handler, [Object? identity]) → void - Set a callback for intercepting messages sent to the platform on the given channel, without decoding them.
-
setMockMessageHandler(
String channel, MessageHandler? handler) → void -
Available on BinaryMessenger, provided by the TestBinaryMessengerExtension extension
Shim for TestDefaultBinaryMessenger.setMockMessageHandler. -
setMockMethodCallHandler(
MethodChannel channel, Future< Object?> ? handler(MethodCall message)?) → void - Set a callback for intercepting method calls sent to the platform on the given channel.
-
setMockStreamHandler(
EventChannel channel, MockStreamHandler? handler) → void - Set a handler for intercepting stream events sent to the platform on the given channel.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited