Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
io.flutter.plugin.common.EventChannel Class Reference

Classes

interface  EventSink
 
interface  StreamHandler
 

Public Member Functions

 EventChannel (BinaryMessenger messenger, String name)
 
 EventChannel (BinaryMessenger messenger, String name, MethodCodec codec)
 
 EventChannel (BinaryMessenger messenger, String name, MethodCodec codec, BinaryMessenger.TaskQueue taskQueue)
 
void setStreamHandler (final StreamHandler handler)
 

Detailed Description

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 MethodCodec used 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 is Object, but only values supported by the specified MethodCodec can be used.

The logical identity of the channel is given by its name. Identically named channels will interfere with each other's communication.

Definition at line 32 of file EventChannel.java.

Constructor & Destructor Documentation

◆ EventChannel() [1/3]

io.flutter.plugin.common.EventChannel.EventChannel ( BinaryMessenger  messenger,
String  name 
)
inline

Creates a new channel associated with the specified BinaryMessenger and with the specified name and the standard MethodCodec.

Parameters
messengera BinaryMessenger.
namea channel name String.

Definition at line 47 of file EventChannel.java.

47 {
48 this(messenger, name, StandardMethodCodec.INSTANCE);
49 }

◆ EventChannel() [2/3]

io.flutter.plugin.common.EventChannel.EventChannel ( BinaryMessenger  messenger,
String  name,
MethodCodec  codec 
)
inline

Creates a new channel associated with the specified BinaryMessenger and with the specified name and MethodCodec.

Parameters
messengera BinaryMessenger.
namea channel name String.
codeca MessageCodec.

Definition at line 59 of file EventChannel.java.

59 {
60 this(messenger, name, codec, null);
61 }

◆ EventChannel() [3/3]

io.flutter.plugin.common.EventChannel.EventChannel ( BinaryMessenger  messenger,
String  name,
MethodCodec  codec,
BinaryMessenger.TaskQueue  taskQueue 
)
inline

Creates a new channel associated with the specified BinaryMessenger and with the specified name and MethodCodec.

Parameters
messengera BinaryMessenger.
namea channel name String.
codeca MessageCodec.
taskQueuea BinaryMessenger.TaskQueue that specifies what thread will execute the handler. Specifying null means execute on the platform thread. See also BinaryMessenger#makeBackgroundTaskQueue().

Definition at line 74 of file EventChannel.java.

78 {
79 if (BuildConfig.DEBUG) {
80 if (messenger == null) {
81 Log.e(TAG, "Parameter messenger must not be null.");
82 }
83 if (name == null) {
84 Log.e(TAG, "Parameter name must not be null.");
85 }
86 if (codec == null) {
87 Log.e(TAG, "Parameter codec must not be null.");
88 }
89 }
90 this.messenger = messenger;
91 this.name = name;
92 this.codec = codec;
93 this.taskQueue = taskQueue;
94 }
void Log(const char *format,...) SK_PRINTF_LIKE(1
Definition: TestRunner.cpp:137

Member Function Documentation

◆ setStreamHandler()

void io.flutter.plugin.common.EventChannel.setStreamHandler ( final StreamHandler  handler)
inline

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
handlera StreamHandler, or null to deregister.

Definition at line 107 of file EventChannel.java.

107 {
108 // We call the 2 parameter variant specifically to avoid breaking changes in
109 // mock verify calls.
110 // See https://github.com/flutter/flutter/issues/92582.
111 if (taskQueue != null) {
112 messenger.setMessageHandler(
113 name, handler == null ? null : new IncomingStreamRequestHandler(handler), taskQueue);
114 } else {
115 messenger.setMessageHandler(
116 name, handler == null ? null : new IncomingStreamRequestHandler(handler));
117 }
118 }
void setMessageHandler(@NonNull String channel, @Nullable BinaryMessageHandler handler)

The documentation for this class was generated from the following file: