FutureBuilder not updating UI even after setState

Viewed 360

I am a complete Flutter begginer. When screen loads for initial time, the data is correctly loaded with getOnlineClass() function. But when I try to update the value of UI, the new data is loaded but the UI does not update.

 return RefreshIndicator(
      onRefresh: () {
        return dataLoader.loadOnlineClass().then((value) => (value){
          print(value);
          listDummy = PersistenceHelper().getOnlineClass();
          setState(() {
            print(listDummy.toString());
          });
        });
      },
      child: FutureBuilder(
        future: listDummy, // async work
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          switch (snapshot.connectionState) {
            case ConnectionState.waiting:
              return Text('Loading....');
            default:
              if (snapshot.hasError)
                return Text('Error: ${snapshot.error}');
              else

                // print(snapshot.data);
                return _listShowerTest(snapshot.data);
          }
        },
      ),
    );
1 Answers

This seems like a typo.

You have given

return dataLoader.loadOnlineClass().then((value) => (value){

But you should use it like this.

return dataLoader.loadOnlineClass().then((value) {

Remove the second (value) part, since when you put it there, your are creating a new function which takes a single parameter. Like this (value) {}.

So, fixed code will be

onRefresh: () {
    return dataLoader.loadOnlineClass().then((value) {
        print(value);
        listDummy = PersistenceHelper().getOnlineClass();
        setState(() {
            // Also you should do some actual state setting here.
            print(listDummy.toString());
        });
    });
},
Related