注册原生组件
class MapPlug {
companion object {
fun registerWith(flutterEngine: FlutterEngine) {
val shimPluginRegistry = ShimPluginRegistry(flutterEngine)
val key = MapPlug::class.java.getCanonicalName()
if (shimPluginRegistry.hasPlugin(key)) return
val registrar = shimPluginRegistry.registrarFor(key)
val mapVF = MapVF(flutterEngine.dartExecutor.binaryMessenger, StandardMessageCodec.INSTANCE)
registrar.platformViewRegistry().registerViewFactory("GoogleMapView", mapVF)
}
}
}
registry 改为 flutterEngine,然后使用
val shimPluginRegistry = ShimPluginRegistry(flutterEngine)
MainActivity中
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
GeneratedPluginRegistrant.registerWith(flutterEngine)
MapPlug.registerWith(flutterEngine)
}
}