Add v1 plugin register function into v2 plugin template (#44166)

This commit is contained in:
xster
2019-11-05 20:03:50 -08:00
committed by GitHub
parent 7aebde1904
commit cf95cd4394
5 changed files with 55 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
/** {{pluginClass}} */
public class {{pluginClass}} implements FlutterPlugin, MethodCallHandler {
@@ -21,6 +22,20 @@ public class {{pluginClass}} implements FlutterPlugin, MethodCallHandler {
channel.setMethodCallHandler(new {{pluginClass}}());
}
// This static function is optional and equivalent to onAttachedToEngine. It supports the old
// pre-Flutter-1.12 Android projects. You are encouraged to continue supporting
// plugin registration via this function while apps migrate to use the new Android APIs
// post-flutter-1.12 via https://flutter.dev/go/android-project-migration.
//
// It is encouraged to share logic between onAttachedToEngine and registerWith to keep
// them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called
// depending on the user's project. onAttachedToEngine or registerWith must both be defined
// in the same class.
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "{{projectName}}");
channel.setMethodCallHandler(new {{pluginClass}}());
}
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
if (call.method.equals("getPlatformVersion")) {