1.12 before

  • Deregister via PluginRegistry
Public static void registerWith(PluginRegistry registry) {// Prevent multiple registrations of final String key = TestFluttertoAndroidTextViewPlugin.class.getCanonicalName();if (registry.hasPlugin(key)) return;
		//初始化 PluginRegistry
		PluginRegistry.Registrar registrar = registry.registrarFor(key);
		//设置标识
		registrar.platformViewRegistry().registerViewFactory("com.flutter_to_native_test_textview", new TestViewFactory(registrar.messenger()));
	}
Copy the code
  • Then call the registration method in MainActivity’s onCteate method
TestFluttertoAndroidTextViewPlugin.registerWith(this)
Copy the code

Version 1.12 and later

  • Deregister through ShimPluginRegistry
class UnityViewRegistrant { fun registerWith(flutterEngine: FlutterEngine) { val key = UnityViewRegistrant::class.java!! .canonicalName val shimPluginRegistry = ShimPluginRegistry(flutterEngine)if (shimPluginRegistry.hasPlugin(key)) return
        val registrar = shimPluginRegistry.registrarFor(key)
        registrar.platformViewRegistry().registerViewFactory("unityView", UnityViewFactory(StandardMessageCodec()))
    }
}
Copy the code
  • The registration method is called in the configureFlutterEngine of MainActivity
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine)
        UnityViewRegistrant().registerWith(flutterEngine)
    }
Copy the code