@@ -13,17 +13,27 @@ import 'text.dart';
13
13
import 'theme.dart' ;
14
14
import 'unread_count_badge.dart' ;
15
15
16
+ typedef OnChannelSelectCallback = void Function (ChannelNarrow narrow);
17
+
16
18
/// Scrollable listing of subscribed streams.
17
19
class SubscriptionListPageBody extends StatefulWidget {
18
20
const SubscriptionListPageBody ({
19
21
super .key,
20
22
this .showTopicListButtonInActionSheet = true ,
21
23
this .hideChannelsIfUserCantPost = false ,
24
+ this .onChannelSelect,
22
25
});
23
26
24
27
final bool showTopicListButtonInActionSheet;
25
28
final bool hideChannelsIfUserCantPost;
26
29
30
+ /// Callback to invoke when the user selects a channel from the list.
31
+ ///
32
+ /// If null, the default behavior is to navigate to the channel feed.
33
+ final OnChannelSelectCallback ? onChannelSelect;
34
+
35
+ // TODO(#412) add onTopicSelect
36
+
27
37
@override
28
38
State <SubscriptionListPageBody > createState () => _SubscriptionListPageBodyState ();
29
39
}
@@ -72,6 +82,16 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
72
82
});
73
83
}
74
84
85
+ void _handleChannelSelect (ChannelNarrow narrow) {
86
+ if (widget.onChannelSelect case final onChannelSelect? ) {
87
+ onChannelSelect (narrow);
88
+ } else {
89
+ Navigator .push (context,
90
+ MessageListPage .buildRoute (context: context,
91
+ narrow: narrow));
92
+ }
93
+ }
94
+
75
95
@override
76
96
Widget build (BuildContext context) {
77
97
// Design referenced from:
@@ -123,14 +143,16 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
123
143
_SubscriptionList (
124
144
unreadsModel: unreadsModel,
125
145
subscriptions: pinned,
126
- showTopicListButtonInActionSheet: widget.showTopicListButtonInActionSheet),
146
+ showTopicListButtonInActionSheet: widget.showTopicListButtonInActionSheet,
147
+ onChannelSelect: _handleChannelSelect),
127
148
],
128
149
if (unpinned.isNotEmpty) ...[
129
150
_SubscriptionListHeader (label: zulipLocalizations.unpinnedSubscriptionsLabel),
130
151
_SubscriptionList (
131
152
unreadsModel: unreadsModel,
132
153
subscriptions: unpinned,
133
- showTopicListButtonInActionSheet: widget.showTopicListButtonInActionSheet),
154
+ showTopicListButtonInActionSheet: widget.showTopicListButtonInActionSheet,
155
+ onChannelSelect: _handleChannelSelect),
134
156
],
135
157
136
158
// TODO(#188): add button leading to "All Streams" page with ability to subscribe
@@ -181,11 +203,13 @@ class _SubscriptionList extends StatelessWidget {
181
203
required this .unreadsModel,
182
204
required this .subscriptions,
183
205
required this .showTopicListButtonInActionSheet,
206
+ required this .onChannelSelect,
184
207
});
185
208
186
209
final Unreads ? unreadsModel;
187
210
final List <Subscription > subscriptions;
188
211
final bool showTopicListButtonInActionSheet;
212
+ final OnChannelSelectCallback onChannelSelect;
189
213
190
214
@override
191
215
Widget build (BuildContext context) {
@@ -199,7 +223,8 @@ class _SubscriptionList extends StatelessWidget {
199
223
return SubscriptionItem (subscription: subscription,
200
224
unreadCount: unreadCount,
201
225
showMutedUnreadBadge: showMutedUnreadBadge,
202
- showTopicListButtonInActionSheet: showTopicListButtonInActionSheet);
226
+ showTopicListButtonInActionSheet: showTopicListButtonInActionSheet,
227
+ onChannelSelect: onChannelSelect);
203
228
});
204
229
}
205
230
}
@@ -212,12 +237,14 @@ class SubscriptionItem extends StatelessWidget {
212
237
required this .unreadCount,
213
238
required this .showMutedUnreadBadge,
214
239
required this .showTopicListButtonInActionSheet,
240
+ required this .onChannelSelect,
215
241
});
216
242
217
243
final Subscription subscription;
218
244
final int unreadCount;
219
245
final bool showMutedUnreadBadge;
220
246
final bool showTopicListButtonInActionSheet;
247
+ final OnChannelSelectCallback onChannelSelect;
221
248
222
249
@override
223
250
Widget build (BuildContext context) {
@@ -230,11 +257,7 @@ class SubscriptionItem extends StatelessWidget {
230
257
// TODO(design) check if this is the right variable
231
258
color: designVariables.background,
232
259
child: InkWell (
233
- onTap: () {
234
- Navigator .push (context,
235
- MessageListPage .buildRoute (context: context,
236
- narrow: ChannelNarrow (subscription.streamId)));
237
- },
260
+ onTap: () => onChannelSelect (ChannelNarrow (subscription.streamId)),
238
261
onLongPress: () => showChannelActionSheet (context,
239
262
channelId: subscription.streamId,
240
263
showTopicListButton: showTopicListButtonInActionSheet),
0 commit comments