2021年1月5日星期二

I have a problem about using FutureBuilder in Flutter

I have a problem about using FutureBuilder in Flutter.

With FutureBuilder, the page is continuously rebuilt.

I've omitted the detailed code to write the question. If you want to see additional code, please leave a comment.

To stop this, What can I do?

Future<bool> initLikes() async {      var list = await ApiProvider().post('/RoomSalesInfo/Select/Like', jsonEncode(          {            "userID" : GlobalProfile.loggedInUser.userID,          }      ));        return true;      } else {        return false;      }    }    //This is the Code that I use in Widget build  FutureBuilder(                      future: initLikes(),                      builder: (BuildContext context, AsyncSnapshot snapshot) {                        //해당 부분은 data를 아직 받아 오지 못했을때 실행되는 부분을 의미한다.                        if (snapshot.hasData == false) {                          return SizedBox();                        }                        //error가 발생하게 될 경우 반환하게 되는 부분                        // 데이터를 정상적으로 받아오게 되면 다음 부분을 실행하게 되는 것이다.                        else {                          return Expanded(                            child: ListView.builder(                                physics: ClampingScrollPhysics(),                                shrinkWrap: true,                                scrollDirection: Axis.vertical,                                controller: _scrollController,                                itemCount: GlobalProfile.listForMe.length +1,                                itemBuilder: (BuildContext context, int index) {                                  if(index == GlobalProfile.listForMe.length){                                    return CupertinoActivityIndicator();                                  }                                  else                                    return  Column();                                }                                ),                          );                        }                      })  
https://stackoverflow.com/questions/65589655/i-have-a-problem-about-using-futurebuilder-in-flutter January 06, 2021 at 11:04AM

没有评论:

发表评论