我正在使用awesome_notifications库,例如,为了防止 * MissingPluginException(在通道plugins.flutter.io/shared_preferences上找不到方法getAll的实现)*,它在AppDelegate中使用:
SwiftAwesomeNotificationsPlugin.setPluginRegistrantCallback { registry in
SwiftAwesomeNotificationsPlugin.register(
with: registry.registrar(forPlugin: "io.flutter.plugins.awesomenotifications.AwesomeNotificationsPlugin")!)
FLTSharedPreferencesPlugin.register(
with: registry.registrar(forPlugin: "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin")!)
}
But I still have error with my custom channel: Unhandled Exception: MissingPluginException(No implementation found for method flutterToWatch on channel it.example.watch) And I don't know how to register it in the background like awesome_notifications do it.
我的频道:
private func initFlutterChannel() {
if let controller = window?.rootViewController as? FlutterViewController {
let channel = FlutterMethodChannel(
name: "it.example.watch",
binaryMessenger: controller.binaryMessenger)
channel.setMethodCallHandler({ [weak self] (
call: FlutterMethodCall,
result: @escaping FlutterResult) -> Void in
switch call.method {
case "flutterToWatch":
guard let watchSession = self?.session, watchSession.isPaired, watchSession.isReachable, let methodData = call.arguments as? [String: Any], let method = methodData["method"], let data = methodData["data"] else {
result(false)
return
}
let watchData: [String: Any] = ["method": method, "data": data]
// Pass the receiving message to Apple Watch
watchSession.sendMessage(watchData, replyHandler: nil, errorHandler: nil)
result(true)
default:
result(FlutterMethodNotImplemented)
}
})
}
}
8条答案
按热度按时间vc6uscn91#
我最近在修改一些软件包时遇到了这个bug。
我刚刚用
flutter clean
清除了Flutter,删除了pubspec.lock和Invalidate and Restard
Android Studio。最后一个flutter pub get
来恢复包,一切都很好。8aqjt8rx2#
我引用https://github.com/flutter/flutter/issues/98473为我解决了这个问题:
总结实际解决方案:在任何需要使用插件的分离菌株的入口点的开始处(您可能已经调用了WidgetsFlutterBinding.ensureInitialized()):
对于Flutter 2.11+(当前的master),调用DartPluginRegistrant.ensureInitialized(),它将为所有需要它的插件运行Dart插件注册。对于较早版本的Flutter,手动调用您使用的任何具有Dart注册的插件实现的registerWith。对于shared_preferences,请参阅上文了解详细信息。
由于后续计划要求分离菌株中存在
DartPluginRegistrant.ensureInitialized()
,因此关闭为已修复。bxgwgixi3#
我在这里遇到了同样的问题,错误出现在AppDelegate.swift中。通过输入以下代码行
我解决了这个问题
yyhrrdl84#
我也面临着错误,
这个页面-Github issue link帮助了我。我在 * pubspec. yaml * 文件中更改了我的插件版本,它为我工作。
您可以在terminal-中使用该命令
4nkexdtk5#
我通过再次运行flutter应用程序修复了这个问题。
ukdjmx9f6#
只需关闭编辑器上运行的应用程序,然后再次启动应用程序(不要热重启/热重载),停止应用程序并再次启动!
vojdkbi07#
如果你遇到这个问题的原因是因为你下载了google_font到你的pub.yaml.请重新启动项目从一个新的,而你的互联网上
lfapxunr8#
这可以通过在build.gradle中的构建类型下进行一些更改来解决
reference: https://developer.android.com/studio/build/shrink-code#kts