Class FlutterFragment.NewEngineFragmentBuilder
- Enclosing class:
- FlutterFragment
FlutterFragment with arguments that correspond to
the values set on this NewEngineFragmentBuilder.
To create a FlutterFragment with default arguments, invoke FlutterFragment.createDefault().
Subclasses of FlutterFragment that do not introduce any new arguments can use this
NewEngineFragmentBuilder to construct instances of the subclass without subclassing
this NewEngineFragmentBuilder. MyFlutterFragment f = new
FlutterFragment.NewEngineFragmentBuilder(MyFlutterFragment.class) .someProperty(...)
.someOtherProperty(...) .build<MyFlutterFragment>();
Subclasses of FlutterFragment that introduce new arguments should subclass this
NewEngineFragmentBuilder to add the new properties:
- Ensure the
FlutterFragmentsubclass has a no-arg constructor. - Subclass this
NewEngineFragmentBuilder. - Override the new
NewEngineFragmentBuilder's no-arg constructor and invoke the super constructor to set theFlutterFragmentsubclass: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.
NewEngineFragmentBuilder subclass is defined, the FlutterFragment
subclass can be instantiated as follows. MyFlutterFragment f = new MyBuilder()
.someExistingProperty(...) .someNewProperty(...) .build<MyFlutterFragment>(); -
Constructor Summary
ConstructorsConstructorDescriptionConstructs aNewEngineFragmentBuilderthat is configured to construct an instance ofFlutterFragment.NewEngineFragmentBuilder(Class<? extends FlutterFragment> subclass) Constructs aNewEngineFragmentBuilderthat is configured to construct an instance ofsubclass, which extendsFlutterFragment. -
Method Summary
Modifier and TypeMethodDescriptionappBundlePath(String appBundlePath) The path to the app bundle which contains the Dart app to execute.<T extends FlutterFragment>
Tbuild()Constructs a newFlutterFragment(or a subclass) that is configured based on properties set on thisBuilder.protected BundleCreates aBundleof arguments that are assigned to the newFlutterFragment.dartEntrypoint(String dartEntrypoint) The name of the initial Dart method to invoke, defaults to "main".dartEntrypointArgs(List<String> dartEntrypointArgs) Arguments passed as a list of string to Dart's entrypoint function.dartLibraryUri(String dartLibraryUri) flutterShellArgs(FlutterShellArgs shellArgs) Any special configuration arguments for the Flutter enginehandleDeeplinking(Boolean handleDeeplinking) Whether to handle the deeplinking from theIntentautomatically if thegetInitialRoutereturns null.initialRoute(String initialRoute) The initial route that a Flutter app will render in thisFlutterFragment, defaults to "/".renderMode(RenderMode renderMode) Render Flutter either as aRenderMode.surfaceor aRenderMode.texture.shouldAttachEngineToActivity(boolean shouldAttachEngineToActivity) Whether or not thisFlutterFragmentshould automatically attach itsActivityas a control surface for itsFlutterEngine.shouldAutomaticallyHandleOnBackPressed(boolean shouldAutomaticallyHandleOnBackPressed) Whether or not thisFlutterFragmentshould automatically receiveFlutterFragment.onBackPressed()events, rather than requiring an explicit activity call through.shouldDelayFirstAndroidViewDraw(boolean shouldDelayFirstAndroidViewDraw) Whether to delay the Android drawing pass till after the Flutter UI has been displayed.transparencyMode(TransparencyMode transparencyMode) Support aTransparencyMode.transparentbackground withinFlutterView, or force anTransparencyMode.opaquebackground.
-
Constructor Details
-
NewEngineFragmentBuilder
public NewEngineFragmentBuilder()Constructs aNewEngineFragmentBuilderthat is configured to construct an instance ofFlutterFragment. -
NewEngineFragmentBuilder
Constructs aNewEngineFragmentBuilderthat is configured to construct an instance ofsubclass, which extendsFlutterFragment.
-
-
Method Details
-
dartEntrypoint
@NonNull public FlutterFragment.NewEngineFragmentBuilder dartEntrypoint(@NonNull String dartEntrypoint) The name of the initial Dart method to invoke, defaults to "main". -
dartLibraryUri
@NonNull public FlutterFragment.NewEngineFragmentBuilder dartLibraryUri(@NonNull String dartLibraryUri) -
dartEntrypointArgs
@NonNull public FlutterFragment.NewEngineFragmentBuilder dartEntrypointArgs(@NonNull List<String> dartEntrypointArgs) Arguments passed as a list of string to Dart's entrypoint function. -
initialRoute
The initial route that a Flutter app will render in thisFlutterFragment, defaults to "/". -
handleDeeplinking
@NonNull public FlutterFragment.NewEngineFragmentBuilder handleDeeplinking(@NonNull Boolean handleDeeplinking) Whether to handle the deeplinking from theIntentautomatically if thegetInitialRoutereturns null. -
appBundlePath
@NonNull public FlutterFragment.NewEngineFragmentBuilder appBundlePath(@NonNull String appBundlePath) The path to the app bundle which contains the Dart app to execute. Null when unspecified, which defaults toFlutterLoader.findAppBundlePath() -
flutterShellArgs
@NonNull public FlutterFragment.NewEngineFragmentBuilder flutterShellArgs(@NonNull FlutterShellArgs shellArgs) Any special configuration arguments for the Flutter engine -
renderMode
Render Flutter either as aRenderMode.surfaceor aRenderMode.texture. You should usesurfaceunless you have a specific reason to usetexture.texturecomes with a significant performance impact, buttexturecan be displayed beneath other AndroidViews and animated, whereassurfacecannot. -
transparencyMode
@NonNull public FlutterFragment.NewEngineFragmentBuilder transparencyMode(@NonNull TransparencyMode transparencyMode) Support aTransparencyMode.transparentbackground withinFlutterView, or force anTransparencyMode.opaquebackground.See
TransparencyModefor implications of this selection. -
shouldAttachEngineToActivity
@NonNull public FlutterFragment.NewEngineFragmentBuilder shouldAttachEngineToActivity(boolean shouldAttachEngineToActivity) Whether or not thisFlutterFragmentshould automatically attach itsActivityas a control surface for itsFlutterEngine.Control surfaces are used to provide Android resources and lifecycle events to plugins that are attached to the
FlutterEngine. IfshouldAttachEngineToActivityis true then thisFlutterFragmentwill connect itsFlutterEngineto 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). IfshouldAttachEngineToActivityis false, then thisFlutterFragmentwill not automatically manage the connection between itsFlutterEngineand the surroundingActivity. TheActivitywill need to be manually connected to thisFlutterFragment'sFlutterEngineby the app developer. SeeFlutterEngine.getActivityControlSurface().One reason that a developer might choose to manually manage the relationship between the
ActivityandFlutterEngineis if the developer wants to move theFlutterEnginesomewhere else. For example, a developer might want theFlutterEngineto outlive the surroundingActivityso that it can be used later in a differentActivity. To accomplish this, theFlutterEnginewill need to be disconnected from the surroundingActivityat an unusual time, preventing thisFlutterFragmentfrom correctly managing the relationship between theFlutterEngineand the surroundingActivity.Another reason that a developer might choose to manually manage the relationship between the
ActivityandFlutterEngineis if the developer wants to prevent, or explicitly control when theFlutterEngine's plugins have access to the surroundingActivity. For example, imagine that thisFlutterFragmentonly 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 theFlutterEngineto have access to theActivity, which can be accomplished by settingshouldAttachEngineToActivitytofalse. -
shouldAutomaticallyHandleOnBackPressed
@NonNull public FlutterFragment.NewEngineFragmentBuilder shouldAutomaticallyHandleOnBackPressed(boolean shouldAutomaticallyHandleOnBackPressed) Whether or not thisFlutterFragmentshould 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.This behavior relies on the implementation of
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.NewEngineFragmentBuilder shouldDelayFirstAndroidViewDraw(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
-
build
Constructs a newFlutterFragment(or a subclass) that is configured based on properties set on thisBuilder.
-