Skip to content

Commit

Permalink
the totalVotes forced to update
Browse files Browse the repository at this point in the history
the underlying totalVotes weren't updating when polloptions changed causing a problem when dividing and failing at the percentage.
This fixes it.

For example: polloptions filled from firebase stream. stream adds 100 votes, polloptions DO update, "totalVotes" doesn't.
  • Loading branch information
shaunramsey committed Jan 24, 2023
1 parent 53716c2 commit dca1ad9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/flutter_polls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@ class FlutterPolls extends HookWidget {
)
.toList()
.first);
final myTotalVotes = pollOptions.fold(0, (acc, option) => acc + option.votes,);
final totalVotes = useState<int>(pollOptions.fold(
0,
(acc, option) => acc + option.votes,
(acc, option) => acc + option.votes,
));
totalVotes.value = myTotalVotes;

return Column(
key: ValueKey(pollId),
Expand Down

0 comments on commit dca1ad9

Please sign in to comment.