@@ -20,6 +20,7 @@ class PollWidget extends StatefulWidget {
2020}
2121
2222class _PollWidgetState extends State <PollWidget > {
23+ final Map <String , bool > _loadingOptions = {};
2324 @override
2425 void initState () {
2526 super .initState ();
@@ -43,30 +44,31 @@ class _PollWidgetState extends State<PollWidget> {
4344
4445 void _modelChanged () {
4546 setState (() {
47+ _loadingOptions.clear ();
4648 // The actual state lives in the [Poll] model.
4749 // This method was called because that just changed.
4850 });
4951 }
5052
5153 void _toggleVote (PollOption option) async {
52- final navigator = Navigator .of (context);
53-
54- unawaited (showDialog (context: context,
55- barrierDismissible: false ,
56- builder: (_) {
57- return Center (child: CircularProgressIndicator ());
58- }
59- ));
60-
6154 final store = PerAccountStoreWidget .of (context);
6255 final op = option.voters.contains (store.selfUserId)
6356 ? PollVoteOp .remove
6457 : PollVoteOp .add;
58+
59+ setState (() {
60+ if (option.voters.contains (store.selfUserId)) {
61+ option.voters.remove (store.selfUserId);
62+ } else {
63+ option.voters.add (store.selfUserId);
64+ }
65+
66+ _loadingOptions[option.key] = true ;
67+ });
68+
6569 await (sendSubmessage (store.connection, messageId: widget.messageId,
6670 submessageType: SubmessageType .widget,
6771 content: PollVoteEventSubmessage (key: option.key, op: op)));
68-
69- navigator.pop ();
7072 }
7173
7274 @override
@@ -95,12 +97,14 @@ class _PollWidgetState extends State<PollWidget> {
9597 .join (', ' );
9698
9799 return Row (
98- crossAxisAlignment: CrossAxisAlignment .baseline ,
100+ crossAxisAlignment: CrossAxisAlignment .center ,
99101 textBaseline: localizedTextBaseline (context),
100102 children: [
101103 GestureDetector (
102104 // TODO: Implement feedback when the user taps the button
103- onTap: () => _toggleVote (option),
105+ onTap: () => _loadingOptions[option.key] ?? false
106+ ? null
107+ : _toggleVote (option),
104108 behavior: HitTestBehavior .translucent,
105109 child: ConstrainedBox (
106110 constraints: const BoxConstraints (minWidth: 44 , minHeight: 44 ),
@@ -117,7 +121,9 @@ class _PollWidgetState extends State<PollWidget> {
117121 // there are more than three digits).
118122 padding: const EdgeInsets .symmetric (horizontal: 4 ),
119123 decoration: BoxDecoration (
120- color: theme.colorPollVoteCountBackground,
124+ color: _loadingOptions[option.key] ?? false
125+ ? theme.colorPollVoteCountBackground.withValues (alpha: 1.0 )
126+ : theme.colorPollVoteCountBackground,
121127 border: Border .all (color: theme.colorPollVoteCountBorder),
122128 borderRadius: BorderRadius .circular (3 )),
123129 child: Center (
0 commit comments