深色模式
在Flutter App中直接使用pigeon与原生平台通信
区别
在App中直接使用pigeon,与在插件中使用pigeon的步骤基本相同,唯一有区别的是,在原生层注册插件的代码不一样。
Android:
kotlin
class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
HelloHostApi.setUp(flutterEngine.dartExecutor.binaryMessenger, api)
}
private val api = object : HelloHostApi {
}
}
iOS:
swift
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let api = AdServiceHostApiImpl()
AdServiceHostApiSetup.setUp(binaryMessenger: controller.binaryMessenger, api: api)
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
private class HelloHostApiImpl : HelloHostApi{
}
}