Class FlutterFragment
- java.lang.Object
-
- androidx.fragment.app.Fragment
-
- io.flutter.embedding.android.FlutterFragment
-
- All Implemented Interfaces:
ComponentCallbacks,ComponentCallbacks2,View.OnCreateContextMenuListener,androidx.lifecycle.LifecycleOwner,androidx.lifecycle.ViewModelStoreOwner,androidx.savedstate.SavedStateRegistryOwner,io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.DelegateFactory,FlutterEngineConfigurator,FlutterEngineProvider,SplashScreenProvider,PlatformPlugin.PlatformPluginDelegate
public class FlutterFragment extends androidx.fragment.app.Fragment implements ComponentCallbacks2, io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.DelegateFactory
Fragmentwhich displays a Flutter UI that takes up all availableFragmentspace.Using a
FlutterFragmentrequires forwarding a number of calls from anActivityto ensure that the internal Flutter app behaves as expected:onPostResume()onBackPressed()onRequestPermissionsResult(int, String[], int[])onNewIntent(Intent)onUserLeaveHint()
onBackPressed()does not need to be called through if the fragment is constructed by one of the builders withshouldAutomaticallyHandleOnBackPressed(true).Additionally, when starting an
Activityfor a result from thisFragment, be sure to invokeFragment.startActivityForResult(Intent, int)rather thanActivity.startActivityForResult(Intent, int). If theActivityversion of the method is invoked then thisFragmentwill never receive itsFragment.onActivityResult(int, int, Intent)callback.If convenient, consider using a
FlutterActivityinstead of aFlutterFragmentto avoid the work of forwarding calls.FlutterFragmentsupports the use of an existing, cachedFlutterEngine. To use a cachedFlutterEngine, ensure that theFlutterEngineis stored inFlutterEngineCacheand then usewithCachedEngine(String)to build aFlutterFragmentwith the cachedFlutterEngine's ID.It is generally recommended to use a cached
FlutterEngineto avoid a momentary delay when initializing a newFlutterEngine. The two exceptions to using a cachedFlutterEngineare:- When
FlutterFragmentis in the firstActivitydisplayed by the app, because pre-warming aFlutterEnginewould have no impact in this situation. - When you are unsure when/if you will need to display a Flutter experience.
The following illustrates how to pre-warm and cache a
FlutterEngine:// Create and pre-warm a FlutterEngine. FlutterEngine flutterEngine = new FlutterEngine(context); flutterEngine .getDartExecutor() .executeDartEntrypoint(DartEntrypoint.createDefault()); // Cache the pre-warmed FlutterEngine in the FlutterEngineCache. FlutterEngineCache.getInstance().put("my_engine", flutterEngine);If Flutter is needed in a location that can only use a
View, consider using aFlutterView. Using aFlutterViewrequires forwarding some calls from anActivity, as well as forwarding lifecycle calls from anActivityor aFragment.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFlutterFragment.CachedEngineFragmentBuilderBuilder that creates a newFlutterFragmentthat uses a cachedFlutterEnginewithargumentsthat correspond to the values set on thisBuilder.static classFlutterFragment.NewEngineFragmentBuilderBuilder that creates a newFlutterFragmentwithargumentsthat correspond to the values set on thisNewEngineFragmentBuilder.
-
Field Summary
Fields Modifier and Type Field Description protected static StringARG_APP_BUNDLE_PATHPath to Flutter's Dart code.protected static StringARG_CACHED_ENGINE_IDThe ID of aFlutterEnginecached inFlutterEngineCachethat will be used within the createdFlutterFragment.protected static StringARG_DART_ENTRYPOINTThe Dart entrypoint method name that is executed upon initialization.protected static StringARG_DART_ENTRYPOINT_ARGSThe Dart entrypoint arguments that is executed upon initialization.protected static StringARG_DART_ENTRYPOINT_URIThe Dart entrypoint method's URI that is executed upon initialization.protected static StringARG_DESTROY_ENGINE_WITH_FRAGMENTTrue if theFlutterEnginein the createdFlutterFragmentshould be destroyed when theFlutterFragmentis destroyed, false if theFlutterEngineshould outlive theFlutterFragment.protected static StringARG_ENABLE_STATE_RESTORATIONTrue if the framework state in the engine attached to this engine should be stored and restored when this fragment is created and destroyed.protected static StringARG_FLUTTER_INITIALIZATION_ARGSFlutter shell arguments.protected static StringARG_FLUTTERVIEW_RENDER_MODEprotected static StringARG_FLUTTERVIEW_TRANSPARENCY_MODEprotected static StringARG_HANDLE_DEEPLINKINGWhether the activity delegate should handle the deeplinking request.protected static StringARG_INITIAL_ROUTEInitial Flutter route that is rendered in a Navigator widget.protected static StringARG_SHOULD_ATTACH_ENGINE_TO_ACTIVITYprotected static StringARG_SHOULD_AUTOMATICALLY_HANDLE_ON_BACK_PRESSEDTrue if the fragment should receiveonBackPressed()events automatically, without requiring an explicit activity call through.protected static StringARG_SHOULD_DELAY_FIRST_ANDROID_VIEW_DRAWWhether to delay the Android drawing pass till after the Flutter UI has been displayed.static intFLUTTER_VIEW_IDThe ID of theFlutterViewcreated by this activity.-
Fields inherited from interface android.content.ComponentCallbacks2
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
-
-
Constructor Summary
Constructors Constructor Description FlutterFragment()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcleanUpFlutterEngine(FlutterEngine flutterEngine)Hook for the host to cleanup references that were established inconfigureFlutterEngine(FlutterEngine)before the host is destroyed or detached.voidconfigureFlutterEngine(FlutterEngine flutterEngine)Configures aFlutterEngineafter its creation.static FlutterFragmentcreateDefault()Creates aFlutterFragmentwith a default configuration.io.flutter.embedding.android.FlutterActivityAndFragmentDelegatecreateDelegate(io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.Host host)Default delegate factory that creates a simple FlutterActivityAndFragmentDelegate instance.voiddetachFromFlutterEngine()ActivitygetActivity()StringgetAppBundlePath()A custom path to the bundle that contains this Flutter app's resources, e.g., Dart code snapshots.StringgetCachedEngineId()Returns the ID of a statically cachedFlutterEngineto use within thisFlutterFragment, ornullif thisFlutterFragmentdoes not want to use a cachedFlutterEngine.ContextgetContext()List<String>getDartEntrypointArgs()The Dart entrypoint arguments will be passed as a list of string to Dart's entrypoint function.StringgetDartEntrypointFunctionName()Returns the name of the Dart method that thisFlutterFragmentshould execute to start a Flutter app.StringgetDartEntrypointLibraryUri()Returns the library URI of the Dart method that thisFlutterFragmentshould execute to start a Flutter app.ExclusiveAppComponent<Activity>getExclusiveAppComponent()Returns the Android App Component exclusively attached toFlutterEngine.FlutterEnginegetFlutterEngine()Hook for subclasses to obtain a reference to theFlutterEnginethat is owned by thisFlutterActivity.FlutterShellArgsgetFlutterShellArgs()FlutterActivityAndFragmentDelegate.Hostmethod that is used byFlutterActivityAndFragmentDelegateto obtain Flutter shell arguments when initializing Flutter.StringgetInitialRoute()Returns the initial route that should be rendered within Flutter, once the Flutter app starts.androidx.lifecycle.LifecyclegetLifecycle()RenderModegetRenderMode()TransparencyModegetTransparencyMode()voidonActivityResult(int requestCode, int resultCode, Intent data)A result has been returned after an invocation ofFragment.startActivityForResult(Intent, int).voidonAttach(Context context)voidonBackPressed()The hardware back button was pressed.voidonCreate(Bundle savedInstanceState)ViewonCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)voidonDestroyView()voidonDetach()voidonFlutterSurfaceViewCreated(FlutterSurfaceView flutterSurfaceView)voidonFlutterTextureViewCreated(FlutterTextureView flutterTextureView)voidonFlutterUiDisplayed()Invoked after theFlutterViewwithin thisFlutterFragmentstarts rendering pixels to the screen.voidonFlutterUiNoLongerDisplayed()Invoked after theFlutterViewwithin thisFlutterFragmentstops rendering pixels to the screen.voidonNewIntent(Intent intent)A new Intent was received by theActivitythat currently owns thisFragment.voidonPause()voidonPostResume()voidonRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)The result of a permission request has been received.voidonResume()voidonSaveInstanceState(Bundle outState)voidonStart()voidonStop()voidonTrimMemory(int level)Callback invoked when memory is low.voidonUserLeaveHint()TheActivitythat owns thisFragmentis about to go to the background as the result of a user's choice/action, i.e., not as the result of an OS decision.booleanpopSystemNavigator()Allow implementer to customize the behavior needed when the Flutter framework calls to pop the Android-side navigation stack.FlutterEngineprovideFlutterEngine(Context context)Hook for subclasses to return aFlutterEnginewith whatever configuration is desired.PlatformPluginprovidePlatformPlugin(Activity activity, FlutterEngine flutterEngine)SplashScreenprovideSplashScreen()Provides aSplashScreento display while Flutter initializes and renders its first frame.booleanshouldAttachEngineToActivity()booleanshouldDestroyEngineWithHost()Returns false if theFlutterEnginewithin thisFlutterFragmentshould outlive theFlutterFragment, itself.booleanshouldDispatchAppLifecycleState()Give the host application a chance to take control of the app lifecycle events.booleanshouldHandleDeeplinking()Whether to handle the deeplinking from theIntentautomatically if thegetInitialRoutereturns null.booleanshouldRestoreAndSaveState()voidupdateSystemUiOverlays()static FlutterFragment.CachedEngineFragmentBuilderwithCachedEngine(String engineId)Returns aFlutterFragment.CachedEngineFragmentBuilderto create aFlutterFragmentwith a cachedFlutterEngineinFlutterEngineCache.static FlutterFragment.NewEngineFragmentBuilderwithNewEngine()Returns aFlutterFragment.NewEngineFragmentBuilderto create aFlutterFragmentwith a newFlutterEngineand a desired engine configuration.-
Methods inherited from class androidx.fragment.app.Fragment
dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSavedStateRegistry, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, getViewLifecycleOwner, getViewLifecycleOwnerLiveData, getViewModelStore, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isStateSaved, isVisible, onActivityCreated, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onDestroy, onDestroyOptionsMenu, onGetLayoutInflater, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onViewCreated, onViewStateRestored, postponeEnterTransition, postponeEnterTransition, registerForContextMenu, requestPermissions, requireActivity, requireArguments, requireContext, requireFragmentManager, requireHost, requireParentFragment, requireView, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, startPostponedEnterTransition, toString, unregisterForContextMenu
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface android.content.ComponentCallbacks
onConfigurationChanged, onLowMemory
-
-
-
-
Field Detail
-
FLUTTER_VIEW_ID
public static final int FLUTTER_VIEW_ID
The ID of theFlutterViewcreated by this activity.This ID can be used to lookup
FlutterViewin the Android view hierarchy. For more, seeView.findViewById(int).
-
ARG_DART_ENTRYPOINT
protected static final String ARG_DART_ENTRYPOINT
The Dart entrypoint method name that is executed upon initialization.- See Also:
- Constant Field Values
-
ARG_DART_ENTRYPOINT_URI
protected static final String ARG_DART_ENTRYPOINT_URI
The Dart entrypoint method's URI that is executed upon initialization.- See Also:
- Constant Field Values
-
ARG_DART_ENTRYPOINT_ARGS
protected static final String ARG_DART_ENTRYPOINT_ARGS
The Dart entrypoint arguments that is executed upon initialization.- See Also:
- Constant Field Values
-
ARG_INITIAL_ROUTE
protected static final String ARG_INITIAL_ROUTE
Initial Flutter route that is rendered in a Navigator widget.- See Also:
- Constant Field Values
-
ARG_HANDLE_DEEPLINKING
protected static final String ARG_HANDLE_DEEPLINKING
Whether the activity delegate should handle the deeplinking request.- See Also:
- Constant Field Values
-
ARG_APP_BUNDLE_PATH
protected static final String ARG_APP_BUNDLE_PATH
Path to Flutter's Dart code.- See Also:
- Constant Field Values
-
ARG_SHOULD_DELAY_FIRST_ANDROID_VIEW_DRAW
protected static final String ARG_SHOULD_DELAY_FIRST_ANDROID_VIEW_DRAW
Whether to delay the Android drawing pass till after the Flutter UI has been displayed.- See Also:
- Constant Field Values
-
ARG_FLUTTER_INITIALIZATION_ARGS
protected static final String ARG_FLUTTER_INITIALIZATION_ARGS
Flutter shell arguments.- See Also:
- Constant Field Values
-
ARG_FLUTTERVIEW_RENDER_MODE
protected static final String ARG_FLUTTERVIEW_RENDER_MODE
- See Also:
- Constant Field Values
-
ARG_FLUTTERVIEW_TRANSPARENCY_MODE
protected static final String ARG_FLUTTERVIEW_TRANSPARENCY_MODE
- See Also:
- Constant Field Values
-
ARG_SHOULD_ATTACH_ENGINE_TO_ACTIVITY
protected static final String ARG_SHOULD_ATTACH_ENGINE_TO_ACTIVITY
- See Also:
- Constant Field Values
-
ARG_CACHED_ENGINE_ID
protected static final String ARG_CACHED_ENGINE_ID
The ID of aFlutterEnginecached inFlutterEngineCachethat will be used within the createdFlutterFragment.- See Also:
- Constant Field Values
-
ARG_DESTROY_ENGINE_WITH_FRAGMENT
protected static final String ARG_DESTROY_ENGINE_WITH_FRAGMENT
True if theFlutterEnginein the createdFlutterFragmentshould be destroyed when theFlutterFragmentis destroyed, false if theFlutterEngineshould outlive theFlutterFragment.- See Also:
- Constant Field Values
-
ARG_ENABLE_STATE_RESTORATION
protected static final String ARG_ENABLE_STATE_RESTORATION
True if the framework state in the engine attached to this engine should be stored and restored when this fragment is created and destroyed.- See Also:
- Constant Field Values
-
ARG_SHOULD_AUTOMATICALLY_HANDLE_ON_BACK_PRESSED
protected static final String ARG_SHOULD_AUTOMATICALLY_HANDLE_ON_BACK_PRESSED
True if the fragment should receiveonBackPressed()events automatically, without requiring an explicit activity call through.- See Also:
- Constant Field Values
-
-
Method Detail
-
createDefault
@NonNull public static FlutterFragment createDefault()
Creates aFlutterFragmentwith a default configuration.FlutterFragment's default configuration creates a newFlutterEnginewithin theFlutterFragmentand uses the following settings:- Dart entrypoint: "main"
- Initial route: "/"
- Render mode: surface
- Transparency mode: transparent
To use a new
FlutterEnginewith different settings, usewithNewEngine().To use a cached
FlutterEngineinstead of creating a new one, usewithCachedEngine(String).
-
withNewEngine
@NonNull public static FlutterFragment.NewEngineFragmentBuilder withNewEngine()
Returns aFlutterFragment.NewEngineFragmentBuilderto create aFlutterFragmentwith a newFlutterEngineand a desired engine configuration.
-
withCachedEngine
@NonNull public static FlutterFragment.CachedEngineFragmentBuilder withCachedEngine(@NonNull String engineId)
Returns aFlutterFragment.CachedEngineFragmentBuilderto create aFlutterFragmentwith a cachedFlutterEngineinFlutterEngineCache.An
IllegalStateExceptionwill be thrown during the lifecycle of theFlutterFragmentif a cachedFlutterEngineis requested but does not exist in the cache.To create a
FlutterFragmentthat uses a newFlutterEngine, usecreateDefault()orwithNewEngine().
-
createDelegate
public io.flutter.embedding.android.FlutterActivityAndFragmentDelegate createDelegate(io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.Host host)
Default delegate factory that creates a simple FlutterActivityAndFragmentDelegate instance.- Specified by:
createDelegatein interfaceio.flutter.embedding.android.FlutterActivityAndFragmentDelegate.DelegateFactory
-
getExclusiveAppComponent
public ExclusiveAppComponent<Activity> getExclusiveAppComponent()
Returns the Android App Component exclusively attached toFlutterEngine.
-
onAttach
public void onAttach(@NonNull Context context)- Overrides:
onAttachin classandroidx.fragment.app.Fragment
-
onCreate
public void onCreate(@Nullable Bundle savedInstanceState)- Overrides:
onCreatein classandroidx.fragment.app.Fragment
-
onCreateView
@Nullable public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
- Overrides:
onCreateViewin classandroidx.fragment.app.Fragment
-
onStart
public void onStart()
- Overrides:
onStartin classandroidx.fragment.app.Fragment
-
onResume
public void onResume()
- Overrides:
onResumein classandroidx.fragment.app.Fragment
-
onPostResume
public void onPostResume()
-
onPause
public void onPause()
- Overrides:
onPausein classandroidx.fragment.app.Fragment
-
onStop
public void onStop()
- Overrides:
onStopin classandroidx.fragment.app.Fragment
-
onDestroyView
public void onDestroyView()
- Overrides:
onDestroyViewin classandroidx.fragment.app.Fragment
-
onSaveInstanceState
public void onSaveInstanceState(Bundle outState)
- Overrides:
onSaveInstanceStatein classandroidx.fragment.app.Fragment
-
detachFromFlutterEngine
public void detachFromFlutterEngine()
-
onDetach
public void onDetach()
- Overrides:
onDetachin classandroidx.fragment.app.Fragment
-
onRequestPermissionsResult
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)The result of a permission request has been received.See
Activity.onRequestPermissionsResult(int, String[], int[])- Overrides:
onRequestPermissionsResultin classandroidx.fragment.app.Fragment- Parameters:
requestCode- identifier passed with the initial permission requestpermissions- permissions that were requestedgrantResults- permission grants or denials
-
onNewIntent
public void onNewIntent(@NonNull Intent intent)A new Intent was received by theActivitythat currently owns thisFragment.- Parameters:
intent- new Intent
-
onBackPressed
public void onBackPressed()
The hardware back button was pressed.If the fragment uses
shouldAutomaticallyHandleOnBackPressed(true), this method should not be called through. It will be called automatically instead.
-
onActivityResult
public void onActivityResult(int requestCode, int resultCode, Intent data)A result has been returned after an invocation ofFragment.startActivityForResult(Intent, int).- Overrides:
onActivityResultin classandroidx.fragment.app.Fragment- Parameters:
requestCode- request code sent withFragment.startActivityForResult(Intent, int)resultCode- code representing the result of theActivitythat was launcheddata- any corresponding return data, held within anIntent
-
onUserLeaveHint
public void onUserLeaveHint()
TheActivitythat owns thisFragmentis about to go to the background as the result of a user's choice/action, i.e., not as the result of an OS decision.
-
onTrimMemory
public void onTrimMemory(int level)
Callback invoked when memory is low.This implementation forwards a memory pressure warning to the running Flutter app.
- Specified by:
onTrimMemoryin interfaceComponentCallbacks2- Parameters:
level- level
-
getFlutterShellArgs
@NonNull public FlutterShellArgs getFlutterShellArgs()
FlutterActivityAndFragmentDelegate.Hostmethod that is used byFlutterActivityAndFragmentDelegateto obtain Flutter shell arguments when initializing Flutter.
-
getCachedEngineId
@Nullable public String getCachedEngineId()
Returns the ID of a statically cachedFlutterEngineto use within thisFlutterFragment, ornullif thisFlutterFragmentdoes not want to use a cachedFlutterEngine.
-
shouldDestroyEngineWithHost
public boolean shouldDestroyEngineWithHost()
Returns false if theFlutterEnginewithin thisFlutterFragmentshould outlive theFlutterFragment, itself.Defaults to true if no custom
is provided, false if a customFlutterEngineis provided.
-
getDartEntrypointFunctionName
@NonNull public String getDartEntrypointFunctionName()
Returns the name of the Dart method that thisFlutterFragmentshould execute to start a Flutter app.Defaults to "main".
Used by this
FlutterFragment'sFlutterActivityAndFragmentDelegate.Host
-
getDartEntrypointArgs
@Nullable public List<String> getDartEntrypointArgs()
The Dart entrypoint arguments will be passed as a list of string to Dart's entrypoint function.A value of null means do not pass any arguments to Dart's entrypoint function.
Subclasses may override this method to directly control the Dart entrypoint arguments.
-
getDartEntrypointLibraryUri
@Nullable public String getDartEntrypointLibraryUri()
Returns the library URI of the Dart method that thisFlutterFragmentshould execute to start a Flutter app.Defaults to null (example value: "package:foo/bar.dart").
Used by this
FlutterFragment'sFlutterActivityAndFragmentDelegate.Host
-
getAppBundlePath
@NonNull public String getAppBundlePath()
A custom path to the bundle that contains this Flutter app's resources, e.g., Dart code snapshots.When unspecified, the value is null, which defaults to the app bundle path defined in
FlutterLoader.findAppBundlePath().Used by this
FlutterFragment'sFlutterActivityAndFragmentDelegate.Host
-
getInitialRoute
@Nullable public String getInitialRoute()
Returns the initial route that should be rendered within Flutter, once the Flutter app starts.Defaults to
null, which signifies a route of "/" in Flutter.Used by this
FlutterFragment'sFlutterActivityAndFragmentDelegate.Host
-
getRenderMode
@NonNull public RenderMode getRenderMode()
Returns the desiredRenderModefor theFlutterViewdisplayed in thisFlutterFragment.Defaults to
RenderMode.surface.Used by this
FlutterFragment'sFlutterActivityAndFragmentDelegate.Host
-
getTransparencyMode
@NonNull public TransparencyMode getTransparencyMode()
Returns the desiredTransparencyModefor theFlutterViewdisplayed in thisFlutterFragment.Defaults to
TransparencyMode.transparent.Used by this
FlutterFragment'sFlutterActivityAndFragmentDelegate.Host
-
provideSplashScreen
@Nullable public SplashScreen provideSplashScreen()
Description copied from interface:SplashScreenProviderProvides aSplashScreento display while Flutter initializes and renders its first frame.- Specified by:
provideSplashScreenin interfaceSplashScreenProvider- Returns:
- The splash screen.
-
provideFlutterEngine
@Nullable public FlutterEngine provideFlutterEngine(@NonNull Context context)
Hook for subclasses to return aFlutterEnginewith whatever configuration is desired.By default this method defers to this
FlutterFragment's surroundingActivity, if thatActivityimplementsFlutterEngineProvider. If this method is overridden, the surroundingActivitywill no longer be given an opportunity to provide aFlutterEngine, unless the subclass explicitly implements that behavior.Consider returning a cached
FlutterEngineinstance from this method to avoid the typical warm-up time that a newFlutterEngineinstance requires.If null is returned then a new default
FlutterEnginewill be created to back thisFlutterFragment.Used by this
FlutterFragment'sFlutterActivityAndFragmentDelegate.Host- Specified by:
provideFlutterEnginein interfaceFlutterEngineProvider- Parameters:
context- The current context. e.g. An activity.- Returns:
- The Flutter engine.
-
getFlutterEngine
@Nullable public FlutterEngine getFlutterEngine()
Hook for subclasses to obtain a reference to theFlutterEnginethat is owned by thisFlutterActivity.
-
providePlatformPlugin
@Nullable public PlatformPlugin providePlatformPlugin(@Nullable Activity activity, @NonNull FlutterEngine flutterEngine)
-
configureFlutterEngine
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine)Configures aFlutterEngineafter its creation.This method is called after
provideFlutterEngine(Context), and after the givenFlutterEnginehas been attached to the owningFragmentActivity. SeeActivityControlSurface.attachToActivity( ExclusiveAppComponent, Lifecycle).It is possible that the owning
FragmentActivityopted not to connect itself as anActivityControlSurface. In that case, any configuration, e.g., plugins, must not expect or depend upon an availableActivityat the time that this method is invoked.The default behavior of this method is to defer to the owning
FragmentActivityas aFlutterEngineConfigurator. Subclasses can override this method if the subclass needs to override theFragmentActivity's behavior, or add to it.Used by this
FlutterFragment'sFlutterActivityAndFragmentDelegate.Host- Specified by:
configureFlutterEnginein interfaceFlutterEngineConfigurator- Parameters:
flutterEngine- The Flutter engine.
-
cleanUpFlutterEngine
public void cleanUpFlutterEngine(@NonNull FlutterEngine flutterEngine)Hook for the host to cleanup references that were established inconfigureFlutterEngine(FlutterEngine)before the host is destroyed or detached.This method is called in
onDetach().- Specified by:
cleanUpFlutterEnginein interfaceFlutterEngineConfigurator- Parameters:
flutterEngine- The Flutter engine.
-
shouldAttachEngineToActivity
public boolean shouldAttachEngineToActivity()
SeeshouldAttachEngineToActivity()andshouldAttachEngineToActivity().Used by this
FlutterFragment'sFlutterActivityAndFragmentDelegate
-
shouldHandleDeeplinking
public boolean shouldHandleDeeplinking()
Whether to handle the deeplinking from theIntentautomatically if thegetInitialRoutereturns null.
-
onFlutterSurfaceViewCreated
public void onFlutterSurfaceViewCreated(@NonNull FlutterSurfaceView flutterSurfaceView)
-
onFlutterTextureViewCreated
public void onFlutterTextureViewCreated(@NonNull FlutterTextureView flutterTextureView)
-
onFlutterUiDisplayed
public void onFlutterUiDisplayed()
Invoked after theFlutterViewwithin thisFlutterFragmentstarts rendering pixels to the screen.This method forwards
onFlutterUiDisplayed()to its attachedActivity, if the attachedActivityimplementsFlutterUiDisplayListener.Subclasses that override this method must call through to the
supermethod.Used by this
FlutterFragment'sFlutterActivityAndFragmentDelegate.Host
-
onFlutterUiNoLongerDisplayed
public void onFlutterUiNoLongerDisplayed()
Invoked after theFlutterViewwithin thisFlutterFragmentstops rendering pixels to the screen.This method forwards
onFlutterUiNoLongerDisplayed()to its attachedActivity, if the attachedActivityimplementsFlutterUiDisplayListener.Subclasses that override this method must call through to the
supermethod.Used by this
FlutterFragment'sFlutterActivityAndFragmentDelegate.Host
-
shouldRestoreAndSaveState
public boolean shouldRestoreAndSaveState()
-
updateSystemUiOverlays
public void updateSystemUiOverlays()
-
shouldDispatchAppLifecycleState
public boolean shouldDispatchAppLifecycleState()
Give the host application a chance to take control of the app lifecycle events.Return
falsemeans the host application dispatches these app lifecycle events, while returntruemeans the engine dispatches these events.Defaults to
true.
-
popSystemNavigator
public boolean popSystemNavigator()
Allow implementer to customize the behavior needed when the Flutter framework calls to pop the Android-side navigation stack.Avoid overriding this method when using
shouldAutomaticallyHandleOnBackPressed(true). If you do, you must alwaysreturn super.popSystemNavigator()rather thanreturn false. Otherwise the navigation behavior will recurse infinitely between this method andonBackPressed(), breaking navigation.- Specified by:
popSystemNavigatorin interfacePlatformPlugin.PlatformPluginDelegate- Returns:
- true if the implementation consumed the pop signal. If false, a default behavior of
finishing the activity or sending the signal to
OnBackPressedDispatcherwill be executed.
-
getContext
@NonNull public abstract Context getContext()
-
getActivity
@Nullable public abstract Activity getActivity()
-
getLifecycle
@NonNull public abstract androidx.lifecycle.Lifecycle getLifecycle()
-
-