@@ -20,6 +20,7 @@ class PollWidget extends StatefulWidget {
20
20
}
21
21
22
22
class _PollWidgetState extends State <PollWidget > {
23
+ final Map <String , bool > _loadingOptions = {};
23
24
@override
24
25
void initState () {
25
26
super .initState ();
@@ -43,30 +44,31 @@ class _PollWidgetState extends State<PollWidget> {
43
44
44
45
void _modelChanged () {
45
46
setState (() {
47
+ _loadingOptions.clear ();
46
48
// The actual state lives in the [Poll] model.
47
49
// This method was called because that just changed.
48
50
});
49
51
}
50
52
51
53
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
-
61
54
final store = PerAccountStoreWidget .of (context);
62
55
final op = option.voters.contains (store.selfUserId)
63
56
? PollVoteOp .remove
64
57
: 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
+
65
69
await (sendSubmessage (store.connection, messageId: widget.messageId,
66
70
submessageType: SubmessageType .widget,
67
71
content: PollVoteEventSubmessage (key: option.key, op: op)));
68
-
69
- navigator.pop ();
70
72
}
71
73
72
74
@override
@@ -95,12 +97,14 @@ class _PollWidgetState extends State<PollWidget> {
95
97
.join (', ' );
96
98
97
99
return Row (
98
- crossAxisAlignment: CrossAxisAlignment .baseline ,
100
+ crossAxisAlignment: CrossAxisAlignment .center ,
99
101
textBaseline: localizedTextBaseline (context),
100
102
children: [
101
103
GestureDetector (
102
104
// TODO: Implement feedback when the user taps the button
103
- onTap: () => _toggleVote (option),
105
+ onTap: () => _loadingOptions[option.key] ?? false
106
+ ? null
107
+ : _toggleVote (option),
104
108
behavior: HitTestBehavior .translucent,
105
109
child: ConstrainedBox (
106
110
constraints: const BoxConstraints (minWidth: 44 , minHeight: 44 ),
@@ -117,7 +121,9 @@ class _PollWidgetState extends State<PollWidget> {
117
121
// there are more than three digits).
118
122
padding: const EdgeInsets .symmetric (horizontal: 4 ),
119
123
decoration: BoxDecoration (
120
- color: theme.colorPollVoteCountBackground,
124
+ color: _loadingOptions[option.key] ?? false
125
+ ? theme.colorPollVoteCountBackground.withValues (alpha: 1.0 )
126
+ : theme.colorPollVoteCountBackground,
121
127
border: Border .all (color: theme.colorPollVoteCountBorder),
122
128
borderRadius: BorderRadius .circular (3 )),
123
129
child: Center (
0 commit comments