没有为'Function'类定义'listen'方法?

问题描述 投票:2回答:2

大家好我正在尝试建立一个颤振来显示纬度和经度,但我仍然得到一个错误,这里是代码:

 void initState(){
    super.initState();
    //Default variable set 0
    currentLocation['latitude'] = 0.0;
    currentLocation['longtitude'] = 0.0;

    initPlatformState();
    locationSubscription = location.onLocationChanged.listen((Map<String, double> result){
      setState(() {
        currentLocation = result;
      });
    });
  }
android dart flutter listen
2个回答
1
投票

onLocationChanged是一个函数,所以你需要调用它来取回流onLocationChanged().listen应该做你需要的。


0
投票

下面的代码对我有用

    var location = new Location();
    location.onLocationChanged().listen((LocationData currentLocation) {
      print(currentLocation.latitude);
      print(currentLocation.longitude);
    });
© www.soinside.com 2019 - 2024. All rights reserved.