在抖动状态下更新图像

时间:2019-09-04 19:54:03

标签: flutter

我有一个listView.builder,其中显示了来自api的数据。 当我从列表项对GestureDetector进行onTap时,我将数据发送到api。 返回数据后,我想更改列表项。 但是我做不到。

例如,我说的一项是这样的:

getIsLikeAccommodation(int _accommodation_id , int _kind ) async {

 if(await checkConnectionInternet()) {
  print(_accommodation_id);
  Map response = await AccommodationService().getIsLikeAccommodation({ "accommodation_id" : _accommodation_id , "is_favorite" : _kind});
  var _responsCode = response['code'];
  var _isLikeResponse = response['accommodation']['is_favorite'];
  if (_responsCode == '1002'){

    After this condition is true , I want the state condition to be checked again and the view changed
  }


  } else {
    _scaffoldKey.currentState.showSnackBar(
      new SnackBar(
        content: new GestureDetector(

          child: new Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              new Text('از اتصال دستگاه به اینترنت مطمئن شوید', style: TextStyle(fontFamily: 'Shabnam')),
              new Icon(Icons.wifi_lock , color: Colors.white)
            ],
          ),
        )
      )
    );
  }
}

Future<bool> checkConnectionInternet() async {
  var connectivityResult = await (new      Connectivity().checkConnectivity());
  return connectivityResult == ConnectivityResult.mobile || connectivityResult == ConnectivityResult.wifi;
 }
}

我连接到服务器:

{{1}}

满足条件

  

如果(_responsCode =='1002')

是真的,我希望再次检查状态条件并更改视图

1 个答案:

答案 0 :(得分:-1)

如果我理解正确,则更改条件后需要调用setState函数。

https://api.flutter.dev/flutter/widgets/State/setState.html