"realtime" ratingbar indicator

Hey, I’m new to Flutter and programming in general, so maybe my question is stupid, but I need some help. On my app I have a screen with 4 ratingbars. (I use the ratingbar package from pub.dev)
When you set a rating on these ratingbars the value of the rating is saved into a variable. Now I have a ratingbar indicator on the same screen and i want that this indicator shows the average rating of the 4 ratingbars above. I tried that the indicator shows the 4 variables divided by 4 but in that case the indicator doesn’t update if i change the rating on one of the 4 ratingbars… so i want the indicator to listen in “realtime” if the variables change and then show a different rating… how is that possible?
I hope someone understand my problem and is able to help :slight_smile:
Greetings, Yoqora

First of all, no question are stupid :slight_smile: We are all here to learn and get better everyday.

Now coming to your query, It would be great if you could share attach a code snippet with your query. From what I have understood, you should use a Stateful class and and have a variable for eg: double avg.
Whenever any of the values change, use

setState(() {avg = values/4});

And then the rating bar indicator should be using this avg value for setting it’s own rating.
Whenever the state of the variable avg changes, the UI will be re-rendered and you will see the results in "real time’.

Feel free to ask here if you have any doubts and do mention here if it worked!

4 Likes

Thank you very much!
It worked just the way you said, I just had to use setState(), didn’t know about that function yet :slight_smile:

1 Like