text
stringlengths
1
474
// Start executing Dart code to pre-warm the FlutterEngine.
flutterEngine.dartExecutor.executeDartEntrypoint(
DartExecutor.DartEntrypoint.createDefault()
)
// Cache the FlutterEngine to be used by FlutterActivity or FlutterFragment.
FlutterEngineCache
.getInstance()
.put("my_engine_id", flutterEngine)
}
}<code_end>
By setting the initial route of the navigation channel, the associated
FlutterEngine displays the desired route upon initial execution of the
runApp() Dart function.Changing the initial route property of the navigation channel
after the initial execution of runApp() has no effect.
Developers who would like to use the same FlutterEngine
between different Activitys and Fragments and switch
the route between those displays need to set up a method channel and
explicitly instruct their Dart code to change Navigator routes.<topic_end>
<topic_start>
Display a splash screen
The initial display of Flutter content requires some wait time,
even if a pre-warmed FlutterEngine is used.
To help improve the user experience around
this brief waiting period, Flutter supports the
display of a splash screen (also known as “launch screen”) until Flutter
renders its first frame. For instructions about how to show a launch
screen, see the splash screen guide.<topic_end>
<topic_start>
Run Flutter with a specified initial route
An Android app might contain many independent Flutter experiences,
running in different FlutterFragments, with different
FlutterEngines. In these scenarios,
it’s common for each Flutter experience to begin with different
initial routes (routes other than /).
To facilitate this, FlutterFragment’s Builder
allows you to specify a desired initial route, as shown:
<code_start>// With a new FlutterEngine.
FlutterFragment flutterFragment = FlutterFragment.withNewEngine()
.initialRoute("myInitialRoute/")
.build();<code_end>
<code_start>// With a new FlutterEngine.
val flutterFragment = FlutterFragment.withNewEngine()
.initialRoute("myInitialRoute/")
.build()<code_end>
info Note
FlutterFragment’s initial route property has no effect when a pre-warmed
FlutterEngine is used because the pre-warmed FlutterEngine already
chose an initial route. The initial route can be chosen explicitly when
pre-warming a FlutterEngine.<topic_end>
<topic_start>
Run Flutter from a specified entrypoint
Similar to varying initial routes, different
FlutterFragments might want to execute different
Dart entrypoints. In a typical Flutter app, there is only one
Dart entrypoint: main(), but you can define other entrypoints.FlutterFragment supports specification of the desired
Dart entrypoint to execute for the given Flutter experience.
To specify an entrypoint, build FlutterFragment, as shown:
<code_start>FlutterFragment flutterFragment = FlutterFragment.withNewEngine()
.dartEntrypoint("mySpecialEntrypoint")
.build();<code_end>
<code_start>val flutterFragment = FlutterFragment.withNewEngine()
.dartEntrypoint("mySpecialEntrypoint")
.build()<code_end>
The FlutterFragment configuration results in the execution
of a Dart entrypoint called mySpecialEntrypoint().
Notice that the parentheses () are
not included in the dartEntrypoint String name.info Note
FlutterFragment’s Dart entrypoint property has no effect
when a pre-warmed FlutterEngine is used because the
pre-warmed FlutterEngine already executed a Dart entrypoint.
The Dart entrypoint can be chosen explicitly when pre-warming
a FlutterEngine.<topic_end>
<topic_start>
Control FlutterFragment’s render mode
FlutterFragment can either use a SurfaceView to render its
Flutter content, or it can use a TextureView.
The default is SurfaceView, which is significantly
better for performance than TextureView. However, SurfaceView
can’t be interleaved in the middle of an Android View hierarchy.
A SurfaceView must either be the bottommost View in the hierarchy,
or the topmost View in the hierarchy.
Additionally, on Android versions before Android N,
SurfaceViews can’t be animated because their layout and rendering
aren’t synchronized with the rest of the View hierarchy.
If either of these use cases are requirements for your app,
then you need to use TextureView instead of SurfaceView.
Select a TextureView by building a FlutterFragment with a
texture RenderMode:
<code_start>// With a new FlutterEngine.
FlutterFragment flutterFragment = FlutterFragment.withNewEngine()
.renderMode(FlutterView.RenderMode.texture)
.build();
// With a cached FlutterEngine.
FlutterFragment flutterFragment = FlutterFragment.withCachedEngine("my_engine_id")
.renderMode(FlutterView.RenderMode.texture)
.build();<code_end>
<code_start>// With a new FlutterEngine.
val flutterFragment = FlutterFragment.withNewEngine()
.renderMode(FlutterView.RenderMode.texture)
.build()