@@ -105,27 +105,44 @@ class ChannelItem extends StatelessWidget {
105
105
overflow: TextOverflow .ellipsis),
106
106
])),
107
107
const SizedBox (width: 8 ),
108
- _ChannelItemSubscriptionToggle (stream: stream),
108
+ _ChannelItemSubscriptionToggle (stream: stream, channelItemContext : context ),
109
109
]))));
110
110
}
111
111
}
112
112
113
- class _ChannelItemSubscriptionToggle extends StatelessWidget {
114
- const _ChannelItemSubscriptionToggle ({required this .stream});
113
+ class _ChannelItemSubscriptionToggle extends StatefulWidget {
114
+ const _ChannelItemSubscriptionToggle ({required this .stream, required this .channelItemContext });
115
115
116
116
final ZulipStream stream;
117
+ final BuildContext channelItemContext;
118
+
119
+ @override
120
+ State <_ChannelItemSubscriptionToggle > createState () => _ChannelItemSubscriptionToggleState ();
121
+ }
122
+
123
+ class _ChannelItemSubscriptionToggleState extends State <_ChannelItemSubscriptionToggle > {
124
+ bool _isLoading = false ;
125
+
126
+ void _setIsLoading (bool value) {
127
+ if (! mounted) return ;
128
+ setState (() => _isLoading = value);
129
+ }
117
130
118
131
@override
119
132
Widget build (BuildContext context) {
120
133
final colorScheme = Theme .of (context).colorScheme;
121
- final (icon, color, onPressed) = stream is Subscription
134
+ final (icon, color, onPressed) = widget. stream is Subscription
122
135
? (Icons .check, colorScheme.primary, _unsubscribeFromChannel)
123
136
: (Icons .add, null , _subscribeToChannel);
124
137
125
138
return IconButton (
126
139
color: color,
127
140
icon: Icon (icon),
128
- onPressed: () => onPressed (context, stream));
141
+ onPressed: _isLoading ? null : () async {
142
+ _setIsLoading (true );
143
+ await onPressed (context, widget.stream);
144
+ _setIsLoading (false );
145
+ });
129
146
}
130
147
131
148
Future <void > _unsubscribeFromChannel (BuildContext context, ZulipStream stream) async {
@@ -175,7 +192,7 @@ class _ChannelItemSubscriptionToggle extends StatelessWidget {
175
192
} catch (e) {
176
193
if (! context.mounted) return ;
177
194
final zulipLocalizations = ZulipLocalizations .of (context);
178
- await showErrorDialog (context: context,
195
+ showErrorDialog (context: context,
179
196
title: zulipLocalizations.errorFailedToSubscribedToChannel (stream.name),
180
197
message: e.toString ()); // TODO(#741): extract user-facing message better
181
198
}
0 commit comments