Why widget in FutureBuilder wont rebuild after finish updating firestore data

Viewed 25

I'm new to flutter and I'm trying to create a widget that consist of user that already accept some invitation and some user that's still pending (user that haven't accept the invitation).

I was able to build the widget after fetching data from the firestore by using their ID to get the user information, and now I'm trying to change the invitation (from inviting user A changed into inviting user B). The data is already updated in firestore but my widget from Future builder won't rebuild. I have to pop the screen first and open it again to see the changes, How can I fix this ? do I have to change this into streamBuilder ?

Here's my code:

Future multipleSolverData ({required BuildContext context}) async {
   //Getting the user information using their ID
}

///Set the data into a variable
void initState() {
  futureSolverData = multipleSolverData(context: context);
  // TODO: implement initState
  super.initState();
}

After setting all the data the widget will be build using this code:

      else if(ticketData['solver_id'].length > 0 || ticketData['temp_solver_id'].length > 0){
        List<Widget> solverWidget = [];
        return FutureBuilder (
            future: futureSolverData,
            builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot){
              if(snapshot.hasData){
                ///Add active solver to solverWidget
                List solverId = snapshot.data['solver']['solver_data'].keys.toList();
                for(int i=0; i < solverId.length; i++){
                  solverWidget.add(
                    /// The Widget
                  );
                }

                ///Add pending solver to solverWidget
                List tempSolverId = snapshot.data['solver']['temp_solver_data'].keys.toList();
                for(int i=0; i < tempSolverId.length; i++){
                  solverWidget.add(
                    /// The Widget
                  );
                }
                return Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: solverWidget,
                );
              }
              else{
                return SizedBox.shrink();
              }

            }
        );
      }

There's also a function to change the user invited. I don't get what's the problem

0 Answers
Related