@@ -95,27 +95,44 @@ class ChannelItem extends StatelessWidget {
95
95
overflow: TextOverflow .ellipsis),
96
96
])),
97
97
const SizedBox (width: 8 ),
98
- _ChannelItemSubscriptionToggle (stream: stream),
98
+ _ChannelItemSubscriptionToggle (stream: stream, channelItemContext : context ),
99
99
]))));
100
100
}
101
101
}
102
102
103
- class _ChannelItemSubscriptionToggle extends StatelessWidget {
104
- const _ChannelItemSubscriptionToggle ({required this .stream});
103
+ class _ChannelItemSubscriptionToggle extends StatefulWidget {
104
+ const _ChannelItemSubscriptionToggle ({required this .stream, required this .channelItemContext });
105
105
106
106
final ZulipStream stream;
107
+ final BuildContext channelItemContext;
108
+
109
+ @override
110
+ State <_ChannelItemSubscriptionToggle > createState () => _ChannelItemSubscriptionToggleState ();
111
+ }
112
+
113
+ class _ChannelItemSubscriptionToggleState extends State <_ChannelItemSubscriptionToggle > {
114
+ bool _isLoading = false ;
115
+
116
+ void _setIsLoading (bool value) {
117
+ if (! mounted) return ;
118
+ setState (() => _isLoading = value);
119
+ }
107
120
108
121
@override
109
122
Widget build (BuildContext context) {
110
123
final colorScheme = Theme .of (context).colorScheme;
111
- final (icon, color, onPressed) = stream is Subscription
124
+ final (icon, color, onPressed) = widget. stream is Subscription
112
125
? (Icons .check, colorScheme.primary, _unsubscribeFromChannel)
113
126
: (Icons .add, null , _subscribeToChannel);
114
127
115
128
return IconButton (
116
129
color: color,
117
130
icon: Icon (icon),
118
- onPressed: () => onPressed (context, stream));
131
+ onPressed: _isLoading ? null : () async {
132
+ _setIsLoading (true );
133
+ await onPressed (context, widget.stream);
134
+ _setIsLoading (false );
135
+ });
119
136
}
120
137
121
138
Future <void > _unsubscribeFromChannel (BuildContext context, ZulipStream stream) async {
@@ -165,7 +182,7 @@ class _ChannelItemSubscriptionToggle extends StatelessWidget {
165
182
} catch (e) {
166
183
if (! context.mounted) return ;
167
184
final zulipLocalizations = ZulipLocalizations .of (context);
168
- await showErrorDialog (context: context,
185
+ showErrorDialog (context: context,
169
186
title: zulipLocalizations.errorFailedToSubscribedToChannel (stream.name),
170
187
message: e.toString ()); // TODO(#741): extract user-facing message better
171
188
}
0 commit comments