text
stringlengths
1
474
// With a cached FlutterEngine.
val flutterFragment = FlutterFragment.withCachedEngine("my_engine_id")
.renderMode(FlutterView.RenderMode.texture)
.build()<code_end>
Using the configuration shown, the resulting FlutterFragment
renders its UI to a TextureView.<topic_end>
<topic_start>
Display a FlutterFragment with transparency
By default, FlutterFragment renders with an opaque background,
using a SurfaceView. (See “Control FlutterFragment’s render
mode.”) That background is black for any pixels that aren’t
painted by Flutter. Rendering with an opaque background is
the preferred rendering mode for performance reasons.
Flutter rendering with transparency on Android negatively
affects performance. However, there are many designs that
require transparent pixels in the Flutter experience that
show through to the underlying Android UI. For this reason,
Flutter supports translucency in a FlutterFragment.info Note
Both SurfaceView and TextureView support transparency.
However, when a SurfaceView is instructed to render with
transparency, it positions itself at a higher z-index than
all other Android Views, which means it appears
above all other Views. This is a limitation of SurfaceView.
If it’s acceptable to render your Flutter experience on top
of all other content, then FlutterFragment’s default
RenderMode of surface is the RenderMode that you
should use. However, if you need to display Android Views both
above and below your Flutter experience, then you must specify a
RenderMode of texture.
See “Control FlutterFragment’s render mode”
for information about controlling the RenderMode.To enable transparency for a FlutterFragment,
build it with the following configuration:
<code_start>// Using a new FlutterEngine.
FlutterFragment flutterFragment = FlutterFragment.withNewEngine()
.transparencyMode(FlutterView.TransparencyMode.transparent)
.build();
// Using a cached FlutterEngine.
FlutterFragment flutterFragment = FlutterFragment.withCachedEngine("my_engine_id")
.transparencyMode(FlutterView.TransparencyMode.transparent)
.build();<code_end>
<code_start>// Using a new FlutterEngine.
val flutterFragment = FlutterFragment.withNewEngine()
.transparencyMode(FlutterView.TransparencyMode.transparent)
.build()
// Using a cached FlutterEngine.
val flutterFragment = FlutterFragment.withCachedEngine("my_engine_id")
.transparencyMode(FlutterView.TransparencyMode.transparent)
.build()<code_end>
<topic_end>
<topic_start>
The relationship between FlutterFragment and its Activity
Some apps choose to use Fragments as entire Android screens.
In these apps, it would be reasonable for a Fragment to
control system chrome like Android’s status bar,
navigation bar, and orientation.In other apps, Fragments are used to represent only
a portion of a UI. A FlutterFragment might be used to
implement the inside of a drawer, a video player,
or a single card. In these situations, it would be
inappropriate for the FlutterFragment to affect
Android’s system chrome because there are other UI
pieces within the same Window.FlutterFragment comes with a concept that helps
differentiate between the case when a FlutterFragment
should be able to control its host Activity, and the
cases when a FlutterFragment should only affect its
own behavior. To prevent a FlutterFragment from
exposing its Activity to Flutter plugins, and to
prevent Flutter from controlling the Activity’s system UI,
use the shouldAttachEngineToActivity() method in
FlutterFragment’s Builder, as shown:
<code_start>// Using a new FlutterEngine.
FlutterFragment flutterFragment = FlutterFragment.withNewEngine()
.shouldAttachEngineToActivity(false)
.build();
// Using a cached FlutterEngine.
FlutterFragment flutterFragment = FlutterFragment.withCachedEngine("my_engine_id")
.shouldAttachEngineToActivity(false)
.build();<code_end>
<code_start>// Using a new FlutterEngine.
val flutterFragment = FlutterFragment.withNewEngine()
.shouldAttachEngineToActivity(false)
.build()
// Using a cached FlutterEngine.
val flutterFragment = FlutterFragment.withCachedEngine("my_engine_id")
.shouldAttachEngineToActivity(false)
.build()<code_end>
Passing false to the shouldAttachEngineToActivity()
Builder method prevents Flutter from interacting with
the surrounding Activity. The default value is true,
which allows Flutter and Flutter plugins to interact with the
surrounding Activity.info Note
Some plugins might expect or require an Activity reference.
Ensure that none of your plugins require an Activity
before you disable access.
<topic_end>
<topic_start>Add a Flutter View to an Android app
warning Warning
Integrating via a FlutterView
is advanced usage and requires manually creating custom, application specific
bindings.Integrating via a FlutterView
requires a bit more work than via FlutterActivity and FlutterFragment previously