e这个问题的答案是我要将pubspec.yl中的Geolocator版本更改为7.0.0

发布于 2025-01-21 16:06:14 字数 432 浏览 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2025-01-28 16:06:14

我假设您在尝试从背景任务或隔离中获取当前位置时会遇到此错误。

问题在于,使用GeoloCator_androidgeolocator_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进行此操作的示例是:

void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) async {
   if (defaultTargetPlatform == TargetPlatform.android) {
     GeolocatorAndroid.registerWith();
   } else if (defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.macOS) {
     GeolocatorApple.registerWith();
   } else if (defaultTargetPlatform == TargetPlatform.linux) {
     GeolocatorLinux.registerWith();
   }

    await Geolocator.checkPermission();
    await Geolocator.getCurrentPosition();
  });
}

如果您运行flutter 2.11+,则可以使用新的dartpluginregistrant.ensureinitialized()方法来确保所有软件包都是正确注册:

void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) async {
    DartPluginRegistrant.ensureInitialized();

    await Geolocator.checkPermission();
    await Geolocator.getCurrentPosition();
  });
}

可以找到更多信息。 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 the geolocator_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 case geolocator_android) is not registered with the platform interface (geolocator_platform_interface) resulting in the MissingPluginException.

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:

void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) async {
   if (defaultTargetPlatform == TargetPlatform.android) {
     GeolocatorAndroid.registerWith();
   } else if (defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.macOS) {
     GeolocatorApple.registerWith();
   } else if (defaultTargetPlatform == TargetPlatform.linux) {
     GeolocatorLinux.registerWith();
   }

    await Geolocator.checkPermission();
    await Geolocator.getCurrentPosition();
  });
}

Alternatively if you are running Flutter 2.11+, you can use the new DartPluginRegistrant.ensureInitialized() method to ensure all packages are registered correctly:

void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) async {
    DartPluginRegistrant.ensureInitialized();

    await Geolocator.checkPermission();
    await Geolocator.getCurrentPosition();
  });
}

More information can be found here and here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文