Flutter位置中的PlatformException(错误,无法获取位置。,null):^ 1.4.1

时间:2019-12-02 09:43:03

标签: android flutter geolocation flutter-dependencies

我得到

  

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);
    }
  }
}

Stacktrace-

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

1 个答案:

答案 0 :(得分:0)

因此,您通过flutter pub get将该包拉入了... 您是否还重建了整个项目? 可能是因为它没有构建插件的本机部分。

Stop and Re-Run可能会有帮助。