Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
io.flutter.embedding.engine.plugins.FlutterPlugin Interface Reference
Inheritance diagram for io.flutter.embedding.engine.plugins.FlutterPlugin:
io.flutter.embedding.engine.plugins.shim.ShimRegistrar io.flutter.plugin.text.ProcessTextPlugin

Classes

interface  FlutterAssets
 
class  FlutterPluginBinding
 

Public Member Functions

void onAttachedToEngine (@NonNull FlutterPluginBinding binding)
 
void onDetachedFromEngine (@NonNull FlutterPluginBinding binding)
 

Detailed Description

Interface to be implemented by all Flutter plugins.

A Flutter plugin allows Flutter developers to interact with a host platform, e.g., Android and iOS, via Dart code. It includes platform code, as well as Dart code. A plugin author is responsible for setting up an appropriate io.flutter.plugin.common.MethodChannel to communicate between platform code and Dart code.

A Flutter plugin has a lifecycle. First, a developer must add a FlutterPlugin to an instance of io.flutter.embedding.engine.FlutterEngine. To do this, obtain a PluginRegistry with FlutterEngine#getPlugins(), then call PluginRegistry#add(FlutterPlugin), passing the instance of the Flutter plugin. During the call to PluginRegistry#add(FlutterPlugin), the io.flutter.embedding.engine.FlutterEngine will invoke onAttachedToEngine(FlutterPluginBinding) on the given FlutterPlugin. If the
FlutterPlugin
is removed from the io.flutter.embedding.engine.FlutterEngine via PluginRegistry#remove(Class), or if the io.flutter.embedding.engine.FlutterEngine is destroyed, the FlutterEngine will invoke FlutterPlugin#onDetachedFromEngine(FlutterPluginBinding) on the given FlutterPlugin.

Once a FlutterPlugin is attached to a io.flutter.embedding.engine.FlutterEngine, the plugin's code is permitted to access and invoke methods on resources within the FlutterPluginBinding that the io.flutter.embedding.engine.FlutterEngine gave to the FlutterPlugin in onAttachedToEngine(FlutterPluginBinding). This includes, for example, the application Context for the running app.

The FlutterPluginBinding provided in onAttachedToEngine(FlutterPluginBinding) is no longer valid after the execution of onDetachedFromEngine(FlutterPluginBinding). Do not access any properties of the FlutterPluginBinding after the completion of onDetachedFromEngine(FlutterPluginBinding).

To register a io.flutter.plugin.common.MethodChannel, obtain a BinaryMessenger via the FlutterPluginBinding.

An Android Flutter plugin may require access to app resources or other artifacts that can only be retrieved through a Context. Developers can access the application context via FlutterPluginBinding#getApplicationContext().

Some plugins may require access to the Activity that is displaying a Flutter experience, or may need to react to Activity lifecycle events, e.g., onCreate(), onStart(), onResume(), onPause(), onStop(), onDestroy(). Any such plugin should implement io.flutter.embedding.engine.plugins.activity.ActivityAware in addition to implementing
FlutterPlugin
. ActivityAware provides callback hooks that expose access to an associated Activity and its Lifecycle. All plugins must respect the possibility that a Flutter experience may never be associated with an Activity, e.g., when Flutter is used for background behavior. Additionally, all plugins must respect that a Activitys may come and go over time, thus requiring plugins to cleanup resources and recreate those resources as the Activity comes and goes.

Definition at line 68 of file FlutterPlugin.java.

Member Function Documentation

◆ onAttachedToEngine()

void io.flutter.embedding.engine.plugins.FlutterPlugin.onAttachedToEngine ( @NonNull FlutterPluginBinding  binding)

This FlutterPlugin has been associated with a io.flutter.embedding.engine.FlutterEngine instance.

Relevant resources that this FlutterPlugin may need are provided via the
binding
. The binding may be cached and referenced until onDetachedFromEngine(FlutterPluginBinding) is invoked and returns.

Implemented in io.flutter.embedding.engine.plugins.shim.ShimRegistrar, and io.flutter.plugin.text.ProcessTextPlugin.

◆ onDetachedFromEngine()

void io.flutter.embedding.engine.plugins.FlutterPlugin.onDetachedFromEngine ( @NonNull FlutterPluginBinding  binding)

This FlutterPlugin has been removed from a io.flutter.embedding.engine.FlutterEngine instance.

The binding passed to this method is the same instance that was passed in onAttachedToEngine(FlutterPluginBinding). It is provided again in this method as a convenience. The binding may be referenced during the execution of this method, but it must not be cached or referenced after this method returns.

FlutterPlugins should release all resources in this method.

Implemented in io.flutter.embedding.engine.plugins.shim.ShimRegistrar, and io.flutter.plugin.text.ProcessTextPlugin.


The documentation for this interface was generated from the following file: