Class FlutterFragment.CachedEngineFragmentBuilder
- java.lang.Object
-
- io.flutter.embedding.android.FlutterFragment.CachedEngineFragmentBuilder
-
- Enclosing class:
- FlutterFragment
public static class FlutterFragment.CachedEngineFragmentBuilder extends Object
Builder that creates a newFlutterFragment
that uses a cachedFlutterEngine
witharguments
that correspond to the values set on thisBuilder
.Subclasses of
FlutterFragment
that do not introduce any new arguments can use thisBuilder
to construct instances of the subclass without subclassing thisBuilder
.MyFlutterFragment f = new FlutterFragment.CachedEngineFragmentBuilder(MyFlutterFragment.class) .someProperty(...) .someOtherProperty(...) .build<MyFlutterFragment>();
Subclasses of
FlutterFragment
that introduce new arguments should subclass thisCachedEngineFragmentBuilder
to add the new properties:- Ensure the
FlutterFragment
subclass has a no-arg constructor. - Subclass this
CachedEngineFragmentBuilder
. - Override the new
CachedEngineFragmentBuilder
's no-arg constructor and invoke the super constructor to set theFlutterFragment
subclass:public MyBuilder() { super(MyFlutterFragment.class); }
- Add appropriate property methods for the new properties.
- Override
createArgs()
, call through to the super method, then add the new properties as arguments in theBundle
.
CachedEngineFragmentBuilder
subclass is defined, theFlutterFragment
subclass can be instantiated as follows.MyFlutterFragment f = new MyBuilder() .someExistingProperty(...) .someNewProperty(...) .build<MyFlutterFragment>();
-
-
Constructor Summary
Constructors Constructor Description CachedEngineFragmentBuilder(Class<? extends FlutterFragment> subclass, String engineId)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends FlutterFragment>
Tbuild()
Constructs a newFlutterFragment
(or a subclass) that is configured based on properties set on thisCachedEngineFragmentBuilder
.protected Bundle
createArgs()
Creates aBundle
of arguments that are assigned to the newFlutterFragment
.FlutterFragment.CachedEngineFragmentBuilder
destroyEngineWithFragment(boolean destroyEngineWithFragment)
Passtrue
to destroy the cachedFlutterEngine
when thisFlutterFragment
is destroyed, orfalse
for the cachedFlutterEngine
to outlive thisFlutterFragment
.FlutterFragment.CachedEngineFragmentBuilder
handleDeeplinking(Boolean handleDeeplinking)
Whether to handle the deeplinking from theIntent
automatically if thegetInitialRoute
returns null.FlutterFragment.CachedEngineFragmentBuilder
renderMode(RenderMode renderMode)
Render Flutter either as aRenderMode.surface
or aRenderMode.texture
.FlutterFragment.CachedEngineFragmentBuilder
shouldAttachEngineToActivity(boolean shouldAttachEngineToActivity)
Whether or not thisFlutterFragment
should automatically attach itsActivity
as a control surface for itsFlutterEngine
.FlutterFragment.CachedEngineFragmentBuilder
shouldAutomaticallyHandleOnBackPressed(boolean shouldAutomaticallyHandleOnBackPressed)
Whether or not thisFlutterFragment
should automatically receiveFlutterFragment.onBackPressed()
events, rather than requiring an explicit activity call through.FlutterFragment.CachedEngineFragmentBuilder
shouldDelayFirstAndroidViewDraw(boolean shouldDelayFirstAndroidViewDraw)
Whether to delay the Android drawing pass till after the Flutter UI has been displayed.FlutterFragment.CachedEngineFragmentBuilder
transparencyMode(TransparencyMode transparencyMode)
Support aTransparencyMode.transparent
background withinFlutterView
, or force anTransparencyMode.opaque
background.
-
-
-
Constructor Detail
-
CachedEngineFragmentBuilder
public CachedEngineFragmentBuilder(@NonNull Class<? extends FlutterFragment> subclass, @NonNull String engineId)
-
-
Method Detail
-
destroyEngineWithFragment
@NonNull public FlutterFragment.CachedEngineFragmentBuilder destroyEngineWithFragment(boolean destroyEngineWithFragment)
Passtrue
to destroy the cachedFlutterEngine
when thisFlutterFragment
is destroyed, orfalse
for the cachedFlutterEngine
to outlive thisFlutterFragment
.
-
renderMode
@NonNull public FlutterFragment.CachedEngineFragmentBuilder renderMode(@NonNull RenderMode renderMode)
Render Flutter either as aRenderMode.surface
or aRenderMode.texture
. You should usesurface
unless you have a specific reason to usetexture
.texture
comes with a significant performance impact, buttexture
can be displayed beneath other AndroidView
s and animated, whereassurface
cannot.
-
transparencyMode
@NonNull public FlutterFragment.CachedEngineFragmentBuilder transparencyMode(@NonNull TransparencyMode transparencyMode)
Support aTransparencyMode.transparent
background withinFlutterView
, or force anTransparencyMode.opaque
background.See
TransparencyMode
for implications of this selection.
-
handleDeeplinking
@NonNull public FlutterFragment.CachedEngineFragmentBuilder handleDeeplinking(@NonNull Boolean handleDeeplinking)
Whether to handle the deeplinking from theIntent
automatically if thegetInitialRoute
returns null.
-
shouldAttachEngineToActivity
@NonNull public FlutterFragment.CachedEngineFragmentBuilder shouldAttachEngineToActivity(boolean shouldAttachEngineToActivity)
Whether or not thisFlutterFragment
should automatically attach itsActivity
as a control surface for itsFlutterEngine
.Control surfaces are used to provide Android resources and lifecycle events to plugins that are attached to the
FlutterEngine
. IfshouldAttachEngineToActivity
is true then thisFlutterFragment
will connect itsFlutterEngine
to the surroundingActivity
, along with any plugins that are registered with thatFlutterEngine
. This allows plugins to access theActivity
, as well as receiveActivity
-specific calls, e.g.,Activity.onNewIntent(Intent)
. IfshouldAttachEngineToActivity
is false, then thisFlutterFragment
will not automatically manage the connection between itsFlutterEngine
and the surroundingActivity
. TheActivity
will need to be manually connected to thisFlutterFragment
'sFlutterEngine
by the app developer. SeeFlutterEngine.getActivityControlSurface()
.One reason that a developer might choose to manually manage the relationship between the
Activity
andFlutterEngine
is if the developer wants to move theFlutterEngine
somewhere else. For example, a developer might want theFlutterEngine
to outlive the surroundingActivity
so that it can be used later in a differentActivity
. To accomplish this, theFlutterEngine
will need to be disconnected from the surroundingActivity
at an unusual time, preventing thisFlutterFragment
from correctly managing the relationship between theFlutterEngine
and the surroundingActivity
.Another reason that a developer might choose to manually manage the relationship between the
Activity
andFlutterEngine
is if the developer wants to prevent, or explicitly control when theFlutterEngine
's plugins have access to the surroundingActivity
. For example, imagine that thisFlutterFragment
only takes up part of the screen and the app developer wants to ensure that none of the Flutter plugins are able to manipulate the surroundingActivity
. In this case, the developer would not want theFlutterEngine
to have access to theActivity
, which can be accomplished by settingshouldAttachEngineToActivity
tofalse
.
-
shouldAutomaticallyHandleOnBackPressed
@NonNull public FlutterFragment.CachedEngineFragmentBuilder shouldAutomaticallyHandleOnBackPressed(boolean shouldAutomaticallyHandleOnBackPressed)
Whether or not thisFlutterFragment
should automatically receiveFlutterFragment.onBackPressed()
events, rather than requiring an explicit activity call through. Disabled by default.When enabled, the activity will automatically dispatch back-press events to the fragment's
OnBackPressedCallback
, instead of requiring the activity to manually callFlutterFragment.onBackPressed()
in client code. If enabled, do not invokeFlutterFragment.onBackPressed()
manually.Enabling this behavior relies on explicit behavior in
FlutterFragment.popSystemNavigator()
. It's not recommended to override that method when enabling this attribute, but if you do, you should always fall back to callingsuper.popSystemNavigator()
when not relying on custom behavior.
-
shouldDelayFirstAndroidViewDraw
@NonNull public FlutterFragment.CachedEngineFragmentBuilder shouldDelayFirstAndroidViewDraw(@NonNull boolean shouldDelayFirstAndroidViewDraw)
Whether to delay the Android drawing pass till after the Flutter UI has been displayed.See {#link FlutterActivityAndFragmentDelegate#onCreateView} for more details.
-
createArgs
@NonNull protected Bundle createArgs()
-
build
@NonNull public <T extends FlutterFragment> T build()
Constructs a newFlutterFragment
(or a subclass) that is configured based on properties set on thisCachedEngineFragmentBuilder
.
-
-