Flutter Engine
The Flutter Engine
|
Classes | |
interface | EngineLifecycleListener |
Package Functions | |
FlutterEngine | spawn ( @NonNull Context context, @NonNull DartEntrypoint dartEntrypoint, @Nullable String initialRoute, @Nullable List< String > dartEntrypointArgs, @Nullable PlatformViewsController platformViewsController, boolean automaticallyRegisterPlugins, boolean waitForRestorationData) |
A single Flutter execution environment.
The FlutterEngine
is the container through which Dart code can be run in an Android application.
Dart code in a FlutterEngine
can execute in the background, or it can be render to the screen by using the accompanying FlutterRenderer
and Dart code using the Flutter framework on the Dart side. Rendering can be started and stopped, thus allowing a
to move from UI interaction to data-only processing and then back to UI interaction.
FlutterEngine
Multiple FlutterEngine
s may exist, execute Dart code, and render UIs within a single Android app. For better memory performance characteristics, construct multiple
s via
FlutterEngineio.flutter.embedding.engine.FlutterEngineGroup
rather than via
's constructor directly.
FlutterEngine
To start running Dart and/or Flutter within this FlutterEngine
, get a reference to this engine's DartExecutor
and then use DartExecutor#executeDartEntrypoint(DartExecutor.DartEntrypoint)
. The DartExecutor#executeDartEntrypoint(DartExecutor.DartEntrypoint)
method must not be invoked twice on the same FlutterEngine
.
To start rendering Flutter content to the screen, use getRenderer()
to obtain a FlutterRenderer
and then attach a RenderSurface
. Consider using a io.flutter.embedding.android.FlutterView
as a RenderSurface
.
Instatiating the first FlutterEngine
per process will also load the Flutter engine's native library and start the Dart VM. Subsequent FlutterEngine
s will run on the same VM instance but will have their own Dart Isolate when the DartExecutor
is run. Each Isolate is a self-contained Dart environment and cannot communicate with each other except via Isolate ports.
Definition at line 83 of file FlutterEngine.java.
|
inline |
Constructs a new FlutterEngine
.
A new FlutterEngine
does not execute any Dart code automatically. See getDartExecutor()
and DartExecutor#executeDartEntrypoint(DartExecutor.DartEntrypoint)
to begin executing Dart code within this FlutterEngine
.
A new FlutterEngine
will not display any UI until a RenderSurface
is registered. See getRenderer()
and FlutterRenderer#startRenderingToSurface(Surface, boolean)
.
A new FlutterEngine
automatically attaches all plugins. See getPlugins()
.
A new FlutterEngine
does come with all default system channels attached.
The first FlutterEngine
instance constructed per process will also load the Flutter native library and start a Dart VM.
In order to pass Dart VM initialization arguments (see io.flutter.embedding.engine.FlutterShellArgs
) when creating the VM, manually set the initialization arguments by calling io.flutter.embedding.engine.loader.FlutterLoader#startInitialization(Context)
and io.flutter.embedding.engine.loader.FlutterLoader#ensureInitializationComplete(Context,
String[])
before constructing the engine.
Definition at line 160 of file FlutterEngine.java.
|
inline |
Same as FlutterEngine(Context)
with added support for passing Dart VM arguments.
If the Dart VM has already started, the given arguments will have no effect.
Definition at line 169 of file FlutterEngine.java.
|
inline |
Same as FlutterEngine(Context)
with added support for passing Dart VM arguments and avoiding automatic plugin registration.
If the Dart VM has already started, the given arguments will have no effect.
Definition at line 179 of file FlutterEngine.java.
|
inline |
Same as FlutterEngine(Context, String[], boolean)
with added support for configuring whether the engine will receive restoration data.
The waitForRestorationData
flag controls whether the engine delays responding to requests from the framework for restoration data until that data has been provided to the engine via RestorationChannel.setRestorationData(byte[] data)
. If the flag is false, the framework may temporarily initialize itself to default values before the restoration data has been made available to the engine. Setting waitForRestorationData
to true avoids this extra work by delaying initialization until the data is available.
When waitForRestorationData
is set,
must be called at a later point in time. If it later turns out that no restoration data is available to restore the framework from, that method must still be called with null as an argument to indicate "no data".
RestorationChannel.setRestorationData(byte[] data)
If the framework never requests the restoration data, this flag has no effect.
Definition at line 209 of file FlutterEngine.java.
|
inline |
Same as FlutterEngine(Context, FlutterLoader, FlutterJNI, String[], boolean)
but with no Dart VM flags and automatically registers plugins.
flutterJNI
should be a new instance that has never been attached to an engine before.
Definition at line 231 of file FlutterEngine.java.
|
inline |
Same as FlutterEngine(Context, FlutterLoader, FlutterJNI)
, plus Dart VM flags in dartVmArgs
, and control over whether plugins are automatically registered with this FlutterEngine
in automaticallyRegisterPlugins
. If plugins are automatically registered, then they are registered during the execution of this constructor.
Definition at line 244 of file FlutterEngine.java.
|
inline |
Same as FlutterEngine(Context, FlutterLoader, FlutterJNI, String[], boolean)
, plus the ability to provide a custom PlatformViewsController
.
Definition at line 263 of file FlutterEngine.java.
|
inline |
Fully configurable FlutterEngine
constructor.
Definition at line 281 of file FlutterEngine.java.
|
inline |
Definition at line 301 of file FlutterEngine.java.
|
inline |
Adds a listener
to be notified of Flutter engine lifecycle events, e.g.,
.
onPreEngineStart()
Definition at line 486 of file FlutterEngine.java.
|
inline |
Cleans up all components within this FlutterEngine
and destroys the associated Dart Isolate. All state held by the Dart Isolate, such as the Flutter Elements tree, is lost.
This FlutterEngine
instance should be discarded after invoking this method.
Definition at line 464 of file FlutterEngine.java.
|
inline |
System channel that sends accessibility requests and events from Flutter to Android.
Definition at line 525 of file FlutterEngine.java.
|
inline |
Definition at line 643 of file FlutterEngine.java.
|
inline |
System channel that sends back gesture commands from Android to Flutter.
Definition at line 549 of file FlutterEngine.java.
|
inline |
Definition at line 653 of file FlutterEngine.java.
|
inline |
Definition at line 658 of file FlutterEngine.java.
|
inline |
The Dart execution context associated with this FlutterEngine
.
The DartExecutor
can be used to start executing Dart code from a given entrypoint. See DartExecutor#executeDartEntrypoint(DartExecutor.DartEntrypoint)
.
Use the DartExecutor
to connect any desired message channels and method channels to facilitate communication between Android and Dart/Flutter.
Definition at line 508 of file FlutterEngine.java.
|
inline |
System channel that allows manual installation and state querying of deferred components.
Definition at line 591 of file FlutterEngine.java.
|
inline |
System channel that sends Android lifecycle events to Flutter.
Definition at line 531 of file FlutterEngine.java.
|
inline |
System channel that sends locale data from Android to Flutter.
Definition at line 537 of file FlutterEngine.java.
|
inline |
The LocalizationPlugin this FlutterEngine created.
Definition at line 629 of file FlutterEngine.java.
|
inline |
System channel that sends and receives text input requests and state.
Definition at line 603 of file FlutterEngine.java.
|
inline |
System channel that sends Flutter navigation commands from Android to Flutter.
Definition at line 543 of file FlutterEngine.java.
|
inline |
System channel that sends platform-oriented requests and information to Flutter, e.g., requests to play sounds, requests for haptics, system chrome settings, etc.
Definition at line 558 of file FlutterEngine.java.
|
inline |
PlatformViewsController
, which controls all platform views running within this
.
FlutterEngine
Definition at line 638 of file FlutterEngine.java.
|
inline |
Plugin registry, which registers plugins that want to be applied to this FlutterEngine
.
Definition at line 623 of file FlutterEngine.java.
|
inline |
System channel that sends text processing requests from Flutter to Android.
Definition at line 564 of file FlutterEngine.java.
|
inline |
The rendering system associated with this FlutterEngine
.
To render a Flutter UI that is produced by this FlutterEngine
's Dart code, attach a RenderSurface
to this FlutterRenderer
.
Definition at line 519 of file FlutterEngine.java.
|
inline |
System channel to exchange restoration data between framework and engine.
The engine can obtain the current restoration data from the framework via this channel to store it on disk and - when the app is relaunched - provide the stored data back to the framework to recreate the original state of the app.
Definition at line 576 of file FlutterEngine.java.
|
inline |
Definition at line 648 of file FlutterEngine.java.
|
inline |
System channel that sends platform/user settings from Android to Flutter, e.g., time format, scale factor, etc.
Definition at line 585 of file FlutterEngine.java.
|
inline |
System channel that sends and receives spell check requests and results.
Definition at line 615 of file FlutterEngine.java.
|
inline |
System channel that sends memory pressure warnings from Android to Flutter.
Definition at line 597 of file FlutterEngine.java.
|
inline |
System channel that sends and receives text input requests and state.
Definition at line 609 of file FlutterEngine.java.
|
inline |
Removes a listener
that was previously added with addEngineLifecycleListener(EngineLifecycleListener)
.
Definition at line 494 of file FlutterEngine.java.
|
inlinepackage |
Create a second io.flutter.embedding.engine.FlutterEngine
based on this current one by sharing as much resources together as possible to minimize startup latency and memory cost.
context | is a Context used to create the io.flutter.embedding.engine.FlutterEngine . Could be the same Context as the current engine or a different one. Generally, only an application Context is needed for the io.flutter.embedding.engine.FlutterEngine and its dependencies. |
dartEntrypoint | specifies the DartEntrypoint the new engine should run. It doesn't need to be the same entrypoint as the current engine but must be built in the same AOT or snapshot. |
initialRoute | The name of the initial Flutter Navigator Route to load. If this is null, it will default to the "/" route. |
dartEntrypointArgs | Arguments passed as a list of string to Dart's entrypoint function. |
io.flutter.embedding.engine.FlutterEngine
. Definition at line 428 of file FlutterEngine.java.
|
inline |
Publishes display metrics to Dart code in Flutter.
Implements io.flutter.util.ViewUtils.DisplayUpdater.
Definition at line 675 of file FlutterEngine.java.