首页 > 解决方案 > Flutter 位置中的 PlatformException(错误,无法获取位置。,null):^1.4.1

问题描述

我正进入(状态

PlatformException(错误,获取位置失败。,null)

使用颤振从设备获取位置时,位置:^1.4.1。任何人都可以帮忙吗?

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    _getLocation();
    return Container();
  }

  Future<Map<String, double>> _getLocation() async {
    var location = new Location();
    try {
      var _permission = await location.hasPermission();
      print(_permission);
      var currentlocation = await location.getLocation();
      print(currentlocation["latitude"]);
      return currentlocation;
    } on Exception catch (e) {
      print(e);
    }
  }
}

堆栈跟踪 -

I/flutter (28694): true
I/flutter (28694): PlatformException(ERROR, Failed to get location., null)

标签: androidfluttergeolocationflutter-dependencies

解决方案


所以你把那个包通过flutter pub get...你也重建了整个项目吗?可能是因为它没有构建插件的本机端。

Stop and Re-Run可能有帮助。


推荐阅读