public class DartExecutor extends Object implements BinaryMessenger
WARNING: THIS CLASS IS EXPERIMENTAL. DO NOT SHIP A DEPENDENCY ON THIS CODE. IF YOU USE IT, WE WILL BREAK YOU.
To specify a top-level Dart function to execute, use a DartExecutor.DartEntrypoint
to tell
DartExecutor
where to find the Dart code to execute, and which Dart function to use as
the entrypoint. To execute the entrypoint, pass the DartExecutor.DartEntrypoint
to
executeDartEntrypoint(DartEntrypoint)
.
To specify a Dart callback to execute, use a DartExecutor.DartCallback
. A given Dart callback must
be registered with the Dart VM to be invoked by a DartExecutor
. To execute the callback,
pass the DartExecutor.DartCallback
to executeDartCallback(DartCallback)
.
TODO(mattcarroll): add a reference to docs about background/plugin execution
Once started, a DartExecutor
cannot be stopped. The associated Dart code will execute
until it completes, or until the FlutterEngine
that owns
this DartExecutor
is destroyed.
Modifier and Type | Class and Description |
---|---|
static class |
DartExecutor.DartCallback
Configuration options that specify which Dart callback function is executed and where
to find that callback and other assets required for Dart execution.
|
static class |
DartExecutor.DartEntrypoint
Configuration options that specify which Dart entrypoint function is executed and where
to find that entrypoint and other assets required for Dart execution.
|
BinaryMessenger.BinaryMessageHandler, BinaryMessenger.BinaryReply
Constructor and Description |
---|
DartExecutor(FlutterJNI flutterJNI) |
Modifier and Type | Method and Description |
---|---|
void |
executeDartCallback(DartExecutor.DartCallback dartCallback)
Starts executing Dart code based on the given
dartCallback . |
void |
executeDartEntrypoint(DartExecutor.DartEntrypoint dartEntrypoint)
Starts executing Dart code based on the given
dartEntrypoint . |
boolean |
isExecutingDart()
Is this
DartExecutor currently executing Dart code? |
void |
onAttachedToJNI()
Invoked when the
FlutterEngine that owns this
DartExecutor attaches to JNI. |
void |
onDetachedFromJNI()
Invoked when the
FlutterEngine that owns this
DartExecutor detaches from JNI. |
void |
send(String channel,
ByteBuffer message)
Sends the given
message from Android to Dart over the given channel . |
void |
send(String channel,
ByteBuffer message,
BinaryMessenger.BinaryReply callback)
Sends the given
messages from Android to Dart over the given channel and
then has the provided callback invoked when the Dart side responds. |
void |
setMessageHandler(String channel,
BinaryMessenger.BinaryMessageHandler handler)
Sets the given
BinaryMessenger.BinaryMessageHandler as the
singular handler for all incoming messages received from the Dart side of this Dart execution
context. |
public DartExecutor(@NonNull FlutterJNI flutterJNI)
public void onAttachedToJNI()
FlutterEngine
that owns this
DartExecutor
attaches to JNI.
When attached to JNI, this DartExecutor
begins handling 2-way communication to/from
the Dart execution context. This communication is facilitate via 2 APIs:
BinaryMessenger
, which sends messages to DartPlatformMessageHandler
, which receives messages from Dartpublic void onDetachedFromJNI()
FlutterEngine
that owns this
DartExecutor
detaches from JNI.
When detached from JNI, this DartExecutor
stops handling 2-way communication to/from
the Dart execution context.
public boolean isExecutingDart()
DartExecutor
currently executing Dart code?public void executeDartEntrypoint(@NonNull DartExecutor.DartEntrypoint dartEntrypoint)
dartEntrypoint
.
See DartExecutor.DartEntrypoint
for configuration options.
dartEntrypoint
- specifies which Dart function to run, and where to find itpublic void executeDartCallback(@NonNull DartExecutor.DartCallback dartCallback)
dartCallback
.
See DartExecutor.DartCallback
for configuration options.
dartCallback
- specifies which Dart callback to run, and where to find itpublic void send(@NonNull String channel, @Nullable ByteBuffer message)
message
from Android to Dart over the given channel
.send
in interface BinaryMessenger
channel
- the name of the logical channel used for the message.message
- the message payload, a direct-allocated ByteBuffer
with the message bytespublic void send(@NonNull String channel, @Nullable ByteBuffer message, @Nullable BinaryMessenger.BinaryReply callback)
messages
from Android to Dart over the given channel
and
then has the provided callback
invoked when the Dart side responds.send
in interface BinaryMessenger
channel
- the name of the logical channel used for the message.message
- the message payload, a direct-allocated ByteBuffer
with the message bytes
between position zero and current position, or null.callback
- a callback invoked when the Dart application responds to the messagepublic void setMessageHandler(@NonNull String channel, @Nullable BinaryMessenger.BinaryMessageHandler handler)
BinaryMessenger.BinaryMessageHandler
as the
singular handler for all incoming messages received from the Dart side of this Dart execution
context.setMessageHandler
in interface BinaryMessenger
channel
- the name of the channel.handler
- a BinaryMessageHandler
to be invoked on incoming messages, or null.