简体   繁体   中英

The method 'listen' isn't defined for the class 'Function'?

Hello everyone I am trying to build a flutter to display the latitude and the longitude but I still get an error here is the code :

捕获 1

卡普特

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

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

Below code is working for me

    var location = new Location();
    location.onLocationChanged().listen((LocationData currentLocation) {
      print(currentLocation.latitude);
      print(currentLocation.longitude);
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM