【问题标题】:The method 'listen' isn't defined for the class 'Function'?方法 'listen' 没有为类 'Function' 定义?
【发布时间】:2019-05-23 11:43:03
【问题描述】:

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

 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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      下面的代码对我有用

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-15
        • 2019-11-02
        • 2021-09-02
        • 1970-01-01
        • 2019-06-24
        • 2021-01-30
        • 2020-09-10
        • 1970-01-01
        相关资源
        最近更新 更多