1
- import 'dart:async' ;
2
-
3
1
import 'package:flutter/material.dart' ;
4
2
5
3
import '../api/model/submessage.dart' ;
@@ -20,6 +18,7 @@ class PollWidget extends StatefulWidget {
20
18
}
21
19
22
20
class _PollWidgetState extends State <PollWidget > {
21
+ final Map <String , bool > _loadingOptions = {};
23
22
@override
24
23
void initState () {
25
24
super .initState ();
@@ -43,6 +42,7 @@ class _PollWidgetState extends State<PollWidget> {
43
42
44
43
void _modelChanged () {
45
44
setState (() {
45
+ _loadingOptions.clear ();
46
46
// The actual state lives in the [Poll] model.
47
47
// This method was called because that just changed.
48
48
});
@@ -53,7 +53,18 @@ class _PollWidgetState extends State<PollWidget> {
53
53
final op = option.voters.contains (store.selfUserId)
54
54
? PollVoteOp .remove
55
55
: 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,
57
68
submessageType: SubmessageType .widget,
58
69
content: PollVoteEventSubmessage (key: option.key, op: op)));
59
70
}
@@ -84,12 +95,14 @@ class _PollWidgetState extends State<PollWidget> {
84
95
.join (', ' );
85
96
86
97
return Row (
87
- crossAxisAlignment: CrossAxisAlignment .baseline ,
98
+ crossAxisAlignment: CrossAxisAlignment .center ,
88
99
textBaseline: localizedTextBaseline (context),
89
100
children: [
90
101
GestureDetector (
91
102
// TODO: Implement feedback when the user taps the button
92
- onTap: () => _toggleVote (option),
103
+ onTap: () => _loadingOptions[option.key] ?? false
104
+ ? null
105
+ : _toggleVote (option),
93
106
behavior: HitTestBehavior .translucent,
94
107
child: ConstrainedBox (
95
108
constraints: const BoxConstraints (minWidth: 44 , minHeight: 44 ),
@@ -106,7 +119,9 @@ class _PollWidgetState extends State<PollWidget> {
106
119
// there are more than three digits).
107
120
padding: const EdgeInsets .symmetric (horizontal: 4 ),
108
121
decoration: BoxDecoration (
109
- color: theme.colorPollVoteCountBackground,
122
+ color: _loadingOptions[option.key] ?? false
123
+ ? theme.colorPollVoteCountBackground.withValues (alpha: 1.0 )
124
+ : theme.colorPollVoteCountBackground,
110
125
border: Border .all (color: theme.colorPollVoteCountBorder),
111
126
borderRadius: BorderRadius .circular (3 )),
112
127
child: Center (
0 commit comments