e这个问题的答案是我要将pubspec.yl中的Geolocator版本更改为7.0.0
E/FLUTTER(13537):[错误:flutter/lib/ui/ui_dart_state.cc(209)]未手动异常:丢失pluguginexception(在频道flutter.baseflow.com/geolocotator.com/geolocotator上找不到用于方法IsLocationserviceenation的实现) E/Flutter(13537):#0 MethodChannel._invokemethod(软件包:flutter/src/services/platform_channel.dart:154:7) E/Flutter(13537): e/flutter(13537):#1 _gettinglocationstate._determineposition(软件包:Flutter_App/main.dart:34:22) E/Flutter(13537): E/Flutter(13537):
E/flutter (13537): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method isLocationServiceEnabled on channel flutter.baseflow.com/geolocator)
E/flutter (13537): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
E/flutter (13537):
E/flutter (13537): #1 _gettinglocationState._determinePosition (package:flutter_app/main.dart:34:22)
E/flutter (13537):
E/flutter (13537):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您在尝试从背景任务或隔离中获取当前位置时会遇到此错误。
问题在于,使用
GeoloCator_android
和geolocator_apple_apple
(ios and MacOS)的版本3.1.6(ios and MacOS)已通过平台特定的实现。但是,由于该任务是在没有摇摆引擎执行的单独执行的单独分离两个中运行的,因此未在平台接口(geolocator_platform_interforf
)注册平台特定的实现(在这种情况下geolocator_android
) )导致缺少Pluginexception
。使用geolocator_android版本3.1.6+或GeoloCator_Apple版本2.1.2+
(这些是Geolocator版本8.0.0的依赖项)确保在启动背景任务时注册平台特定的实现。关于如何使用
Workmanager
进行此操作的示例是:如果您运行flutter 2.11+,则可以使用新的
dartpluginregistrant.ensureinitialized()
方法来确保所有软件包都是正确注册:可以找到更多信息。 href =“ https://github.com/flutter/flutter/issues/98473#issuecomment-1060952450” rel =“ nofollow noreferrer”>在这里。
I am assuming you get this error when trying to acquire the current position from a background task or isolate.
The problem with this is that with version 3.1.6 of the
geolocator_android
and version 2.1.2 of thegeolocator_apple
(iOS and macOS) the default method channel implementation has been replaced by a platform specific implementation. However since the task is run in a separate isolate which executes without the Flutter engine, the platform specific implementation (in this casegeolocator_android
) is not registered with the platform interface (geolocator_platform_interface
) resulting in theMissingPluginException
.To use geolocator_android version 3.1.6+ or geolocator_apple version 2.1.2+
(these are dependencies of geolocator version 8.0.0) make sure you register the platform specific implementation when the background task is started. Examples on how to accomplish this using the
Workmanager
are:Alternatively if you are running Flutter 2.11+, you can use the new
DartPluginRegistrant.ensureInitialized()
method to ensure all packages are registered correctly:More information can be found here and here.