Search code examples
androiddartflutterlisten

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 :

capture 1

capute

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

Solution

  • onLocationChanged is a function, so you need to call it to get back the stream onLocationChanged().listen should do what you need.