Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose and Usage of `GeneratedPluginRegistrant.class` when developing Native Plugin

I'm currently building a Plugin to make use of native API's on Android and iOS.

I've written MyPlugin which implements MethodCallHandler. In my plugin project, I have an example app. This example app has a generated class GeneratedPluginRegistrant.class, which calls the static method registerWith. All of this is used as a one liner in the MainActivity.

I have several questions.

  1. It seems that MyPlugin must match the name of the plugin project. IE - project is flutter_tools, my plugin must be named FlutterToolsPlugin, otherwise GeneratedPluginRegistrant will break. How is GeneratedPluginRegistrant generated?

  2. What is the purpose of GeneratedPluginRegistrant?

  3. What is actually happening to my plugin when it is registered?

  4. If I want to use MyPlugin, can it be done so without the GeneratedPluginRegistrant? I wish to respond to lifecycle methods like onActivityResult, and it seems this encapsulation prevents me from interacting with the plugin directly in the FlutterActivity.

  5. Can I interact with other native plugins from my own on the native side without having to go back and forth through Dart?

like image 631
Elli White Avatar asked Oct 23 '18 22:10

Elli White


People also ask

What is GeneratedPluginRegistrant?

The GeneratedPluginRegistrant is automatically generated by a FlutterApplication in order to register plugins defined in your Flutter App's pubspec.yaml file.

How do you get activity on Flutter plugin?

Show activity on this post. activity = binding. activity; should be activity = binding. getActivity(); Else code works great for me!

What is Generated_plugin_registrant Dart?

generated_plugin_registrant. dart is an automatically generated file that is required to compile your Flutter project as a web application: This file generated_plugin_registrant. dart exists only to support the web. It exists if Flutter is web-enabled and there is at least one package that has asked for it.


1 Answers

The GeneratedPluginRegistrant is automatically generated by a FlutterApplication in order to register plugins defined in your Flutter App's pubspec.yaml file. By providing an instance of PluginRegistry like FlutterActivity to the GeneratedPluginRegistrant#registerWith function you enable interactions between your Flutter Plugins and your Android APIs. see @PluginRegistry Documentation

like image 200
feilong Avatar answered Oct 01 '22 12:10

feilong