From dca1ad98f1730214ab5799b263b03a94f019604e Mon Sep 17 00:00:00 2001 From: Shaun Ramsey Date: Tue, 24 Jan 2023 16:09:22 -0500 Subject: [PATCH] the totalVotes forced to update 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. --- lib/flutter_polls.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/flutter_polls.dart b/lib/flutter_polls.dart index cefbabc..8e49b19 100644 --- a/lib/flutter_polls.dart +++ b/lib/flutter_polls.dart @@ -222,10 +222,12 @@ class FlutterPolls extends HookWidget { ) .toList() .first); + final myTotalVotes = pollOptions.fold(0, (acc, option) => acc + option.votes,); final totalVotes = useState(pollOptions.fold( 0, - (acc, option) => acc + option.votes, + (acc, option) => acc + option.votes, )); + totalVotes.value = myTotalVotes; return Column( key: ValueKey(pollId),