Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
io.flutter.plugin.common.MethodChannel Class Reference

Classes

interface  MethodCallHandler
 
interface  Result
 

Public Member Functions

 MethodChannel (@NonNull BinaryMessenger messenger, @NonNull String name)
 
 MethodChannel ( @NonNull BinaryMessenger messenger, @NonNull String name, @NonNull MethodCodec codec)
 
 MethodChannel ( @NonNull BinaryMessenger messenger, @NonNull String name, @NonNull MethodCodec codec, @Nullable BinaryMessenger.TaskQueue taskQueue)
 
void invokeMethod (@NonNull String method, @Nullable Object arguments)
 
void invokeMethod ( @NonNull String method, @Nullable Object arguments, @Nullable Result callback)
 
void setMethodCallHandler (final @Nullable MethodCallHandler handler)
 
void resizeChannelBuffer (int newSize)
 
void setWarnsOnChannelOverflow (boolean warns)
 

Detailed Description

A named channel for communicating with the Flutter application using asynchronous method calls.

Incoming method calls are decoded from binary on receipt, and Java results 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 a MethodChannel counterpart of this channel on the Dart side. The Java type of method call arguments and results 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 29 of file MethodChannel.java.

Constructor & Destructor Documentation

◆ MethodChannel() [1/3]

io.flutter.plugin.common.MethodChannel.MethodChannel ( @NonNull BinaryMessenger  messenger,
@NonNull 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 44 of file MethodChannel.java.

44 {
45 this(messenger, name, StandardMethodCodec.INSTANCE);
46 }

◆ MethodChannel() [2/3]

io.flutter.plugin.common.MethodChannel.MethodChannel ( @NonNull BinaryMessenger  messenger,
@NonNull String  name,
@NonNull 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 56 of file MethodChannel.java.

57 {
58 this(messenger, name, codec, null);
59 }

◆ MethodChannel() [3/3]

io.flutter.plugin.common.MethodChannel.MethodChannel ( @NonNull BinaryMessenger  messenger,
@NonNull String  name,
@NonNull MethodCodec  codec,
@Nullable 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 72 of file MethodChannel.java.

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

Member Function Documentation

◆ invokeMethod() [1/2]

void io.flutter.plugin.common.MethodChannel.invokeMethod ( @NonNull String  method,
@Nullable Object  arguments,
@Nullable Result  callback 
)
inline

Invokes a method on this channel, optionally expecting a result.

Any uncaught exception thrown by the result callback will be caught and logged.

Parameters
methodthe name String of the method.
argumentsthe arguments for the invocation, possibly null.
callbacka Result callback for the invocation result, or null.

Definition at line 115 of file MethodChannel.java.

116 {
117 messenger.send(
118 name,
119 codec.encodeMethodCall(new MethodCall(method, arguments)),
120 callback == null ? null : new IncomingResultHandler(callback));
121 }
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static ::testing::Matcher< GBytes * > MethodCall(const std::string &name, ::testing::Matcher< FlValue * > args)
void send(@NonNull String channel, @Nullable ByteBuffer message)
ByteBuffer encodeMethodCall(@NonNull MethodCall methodCall)

◆ invokeMethod() [2/2]

void io.flutter.plugin.common.MethodChannel.invokeMethod ( @NonNull String  method,
@Nullable Object  arguments 
)
inline

Invokes a method on this channel, expecting no result.

Parameters
methodthe name String of the method.
argumentsthe arguments for the invocation, possibly null.

Definition at line 101 of file MethodChannel.java.

101 {
102 invokeMethod(method, arguments, null);
103 }
void invokeMethod(@NonNull String method, @Nullable Object arguments)

◆ resizeChannelBuffer()

void io.flutter.plugin.common.MethodChannel.resizeChannelBuffer ( int  newSize)
inline

Adjusts the number of messages that will get buffered when sending messages to channels that aren't fully set up yet. For example, the engine isn't running yet or the channel's message handler isn't set up on the Dart side yet.

Definition at line 156 of file MethodChannel.java.

156 {
157 BasicMessageChannel.resizeChannelBuffer(messenger, name, newSize);
158 }

◆ setMethodCallHandler()

void io.flutter.plugin.common.MethodChannel.setMethodCallHandler ( final @Nullable MethodCallHandler  handler)
inline

Registers a method call handler on this channel.

Overrides any existing handler registration for (the name of) this channel.

If no handler has been registered, any incoming method call on this channel will be handled silently by sending a null reply. This results in a MissingPluginException on the Dart side, unless an OptionalMethodChannel is used.

Parameters
handlera MethodCallHandler, or null to deregister.

Definition at line 138 of file MethodChannel.java.

138 {
139 // We call the 2 parameter variant specifically to avoid breaking changes in
140 // mock verify calls.
141 // See https://github.com/flutter/flutter/issues/92582.
142 if (taskQueue != null) {
143 messenger.setMessageHandler(
144 name, handler == null ? null : new IncomingMethodCallHandler(handler), taskQueue);
145 } else {
146 messenger.setMessageHandler(
147 name, handler == null ? null : new IncomingMethodCallHandler(handler));
148 }
149 }
void setMessageHandler(@NonNull String channel, @Nullable BinaryMessageHandler handler)

◆ setWarnsOnChannelOverflow()

void io.flutter.plugin.common.MethodChannel.setWarnsOnChannelOverflow ( boolean  warns)
inline

Toggles whether the channel should show warning messages when discarding messages due to overflow. When 'warns' is false the channel is expected to overflow and warning messages will not be shown.

Definition at line 165 of file MethodChannel.java.

165 {
166 BasicMessageChannel.setWarnsOnChannelOverflow(messenger, name, warns);
167 }

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