Class EventChannel
- java.lang.Object
-
- io.flutter.plugin.common.EventChannel
-
public final class EventChannel extends Object
A named channel for communicating with the Flutter application using asynchronous event streams.Incoming requests for event stream setup are decoded from binary on receipt, and Java responses and events are encoded into binary before being transmitted back to Flutter. The
MethodCodecused must be compatible with the one used by the Flutter application. This can be achieved by creating an EventChannel counterpart of this channel on the Dart side. The Java type of stream configuration arguments, events, and error details isObject, but only values supported by the specifiedMethodCodeccan be used.The logical identity of the channel is given by its name. Identically named channels will interfere with each other's communication.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceEventChannel.EventSinkEvent callback.static interfaceEventChannel.StreamHandlerHandler of stream setup and teardown requests.
-
Constructor Summary
Constructors Constructor Description EventChannel(BinaryMessenger messenger, String name)Creates a new channel associated with the specifiedBinaryMessengerand with the specified name and the standardMethodCodec.EventChannel(BinaryMessenger messenger, String name, MethodCodec codec)Creates a new channel associated with the specifiedBinaryMessengerand with the specified name andMethodCodec.EventChannel(BinaryMessenger messenger, String name, MethodCodec codec, BinaryMessenger.TaskQueue taskQueue)Creates a new channel associated with the specifiedBinaryMessengerand with the specified name andMethodCodec.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidsetStreamHandler(EventChannel.StreamHandler handler)Registers a stream handler on this channel.
-
-
-
Constructor Detail
-
EventChannel
public EventChannel(BinaryMessenger messenger, String name)
Creates a new channel associated with the specifiedBinaryMessengerand with the specified name and the standardMethodCodec.- Parameters:
messenger- aBinaryMessenger.name- a channel name String.
-
EventChannel
public EventChannel(BinaryMessenger messenger, String name, MethodCodec codec)
Creates a new channel associated with the specifiedBinaryMessengerand with the specified name andMethodCodec.- Parameters:
messenger- aBinaryMessenger.name- a channel name String.codec- aMessageCodec.
-
EventChannel
public EventChannel(BinaryMessenger messenger, String name, MethodCodec codec, BinaryMessenger.TaskQueue taskQueue)
Creates a new channel associated with the specifiedBinaryMessengerand with the specified name andMethodCodec.- Parameters:
messenger- aBinaryMessenger.name- a channel name String.codec- aMessageCodec.taskQueue- aBinaryMessenger.TaskQueuethat specifies what thread will execute the handler. Specifying null means execute on the platform thread. See alsoBinaryMessenger.makeBackgroundTaskQueue().
-
-
Method Detail
-
setStreamHandler
@UiThread public void setStreamHandler(EventChannel.StreamHandler handler)
Registers a stream handler on this channel.Overrides any existing handler registration for (the name of) this channel.
If no handler has been registered, any incoming stream setup requests will be handled silently by providing an empty stream.
- Parameters:
handler- aEventChannel.StreamHandler, or null to deregister.
-
-