0

For some weird reason, after searching for the second time, given I already have a list with the first search results, when I click on an element it displays information from the first search result. I don't understand why.

return Expanded(
      child: FutureBuilder(
          future: showSearchObject,
          builder: (context, AsyncSnapshot<AllTVShowList> snapshot) {
            if ( !snapshot.hasData){
              ...
            }
            else{
              ....
              return Column(
                  children: [
                    Expanded(
                      child: Container(
                          height: _height,
                          child: ListView.builder(
                            scrollDirection: Axis.vertical,
                            shrinkWrap: true,
                            itemCount: snapshot.data.showList.length,
                            itemBuilder: (context, int index) {
                              print(snapshot.data.showList[index].name);
                              return ShowCard(show: snapshot.data.showList[index]);
                            },
                          ),
                        ),
                    ),
                  ],
              );
            }
          }
      ),
  );
w1nt_r
  • 1
  • Every time you execute a search you should set the state of the widget so that FutureBuilder can be reset using the new search query. – Badr B Aug 22 '20 at 06:24
  • I also noticed it's only happening to the list elements which are visible, when I scroll I can see they are getting updated, but the first 3 which are visible got the content from the previous search. – w1nt_r Aug 22 '20 at 06:31
  • Like their init it's not calling after they are buing built – w1nt_r Aug 22 '20 at 06:32
  • Hmm, can you post your `showSearchObject` function? – Badr B Aug 22 '20 at 06:46
  • Future showSearchObject; -declaration – w1nt_r Aug 22 '20 at 06:53
  • _searchShows(String text) { setState(() { _showName = text; _searched = true; showSearchObject = getSearchResults(showName: _showName); }); } //On submitting the textfield calling the function. onSubmitted: (value) { _searchShows(value); _icon = Icon(Icons.search, color: Colors.white,); }, – w1nt_r Aug 22 '20 at 06:54
  • `onSubmitted: (value) { _searchShows(value); _icon = Icon(Icons.search, color: Colors.white,); },` – w1nt_r Aug 22 '20 at 06:55

0 Answers0