1- import 'dart:async' ;
2-
31import 'package:flutter/material.dart' ;
42
53import '../api/model/submessage.dart' ;
@@ -20,6 +18,7 @@ class PollWidget extends StatefulWidget {
2018}
2119
2220class _PollWidgetState extends State <PollWidget > {
21+ final Map <String , bool > _loadingOptions = {};
2322 @override
2423 void initState () {
2524 super .initState ();
@@ -43,6 +42,7 @@ class _PollWidgetState extends State<PollWidget> {
4342
4443 void _modelChanged () {
4544 setState (() {
45+ _loadingOptions.clear ();
4646 // The actual state lives in the [Poll] model.
4747 // This method was called because that just changed.
4848 });
@@ -53,7 +53,18 @@ class _PollWidgetState extends State<PollWidget> {
5353 final op = option.voters.contains (store.selfUserId)
5454 ? PollVoteOp .remove
5555 : PollVoteOp .add;
56- unawaited (sendSubmessage (store.connection, messageId: widget.messageId,
56+
57+ setState (() {
58+ if (option.voters.contains (store.selfUserId)) {
59+ option.voters.remove (store.selfUserId);
60+ } else {
61+ option.voters.add (store.selfUserId);
62+ }
63+
64+ _loadingOptions[option.key] = true ;
65+ });
66+
67+ await (sendSubmessage (store.connection, messageId: widget.messageId,
5768 submessageType: SubmessageType .widget,
5869 content: PollVoteEventSubmessage (key: option.key, op: op)));
5970 }
@@ -84,12 +95,14 @@ class _PollWidgetState extends State<PollWidget> {
8495 .join (', ' );
8596
8697 return Row (
87- crossAxisAlignment: CrossAxisAlignment .baseline ,
98+ crossAxisAlignment: CrossAxisAlignment .center ,
8899 textBaseline: localizedTextBaseline (context),
89100 children: [
90101 GestureDetector (
91102 // TODO: Implement feedback when the user taps the button
92- onTap: () => _toggleVote (option),
103+ onTap: () => _loadingOptions[option.key] ?? false
104+ ? null
105+ : _toggleVote (option),
93106 behavior: HitTestBehavior .translucent,
94107 child: ConstrainedBox (
95108 constraints: const BoxConstraints (minWidth: 44 , minHeight: 44 ),
@@ -106,7 +119,9 @@ class _PollWidgetState extends State<PollWidget> {
106119 // there are more than three digits).
107120 padding: const EdgeInsets .symmetric (horizontal: 4 ),
108121 decoration: BoxDecoration (
109- color: theme.colorPollVoteCountBackground,
122+ color: _loadingOptions[option.key] ?? false
123+ ? theme.colorPollVoteCountBackground.withValues (alpha: 1.0 )
124+ : theme.colorPollVoteCountBackground,
110125 border: Border .all (color: theme.colorPollVoteCountBorder),
111126 borderRadius: BorderRadius .circular (3 )),
112127 child: Center (
0 commit comments