@@ -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,12 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
72
82
});
73
83
}
74
84
85
+ void _handleChannelSelect (ChannelNarrow narrow) {
86
+ Navigator .push (context,
87
+ MessageListPage .buildRoute (context: context,
88
+ narrow: narrow));
89
+ }
90
+
75
91
@override
76
92
Widget build (BuildContext context) {
77
93
// Design referenced from:
@@ -114,6 +130,8 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
114
130
message: zulipLocalizations.channelsEmptyPlaceholder);
115
131
}
116
132
133
+ final onChannelSelect = widget.onChannelSelect ?? _handleChannelSelect;
134
+
117
135
return SafeArea ( // horizontal insets
118
136
child: CustomScrollView (
119
137
slivers: [
@@ -122,14 +140,16 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
122
140
_SubscriptionList (
123
141
unreadsModel: unreadsModel,
124
142
subscriptions: pinned,
125
- showTopicListButtonInActionSheet: widget.showTopicListButtonInActionSheet),
143
+ showTopicListButtonInActionSheet: widget.showTopicListButtonInActionSheet,
144
+ onChannelSelect: onChannelSelect),
126
145
],
127
146
if (unpinned.isNotEmpty) ...[
128
147
_SubscriptionListHeader (label: zulipLocalizations.unpinnedSubscriptionsLabel),
129
148
_SubscriptionList (
130
149
unreadsModel: unreadsModel,
131
150
subscriptions: unpinned,
132
- showTopicListButtonInActionSheet: widget.showTopicListButtonInActionSheet),
151
+ showTopicListButtonInActionSheet: widget.showTopicListButtonInActionSheet,
152
+ onChannelSelect: onChannelSelect),
133
153
],
134
154
135
155
// TODO(#188): add button leading to "All Streams" page with ability to subscribe
@@ -180,11 +200,13 @@ class _SubscriptionList extends StatelessWidget {
180
200
required this .unreadsModel,
181
201
required this .subscriptions,
182
202
required this .showTopicListButtonInActionSheet,
203
+ required this .onChannelSelect,
183
204
});
184
205
185
206
final Unreads ? unreadsModel;
186
207
final List <Subscription > subscriptions;
187
208
final bool showTopicListButtonInActionSheet;
209
+ final OnChannelSelectCallback onChannelSelect;
188
210
189
211
@override
190
212
Widget build (BuildContext context) {
@@ -198,7 +220,8 @@ class _SubscriptionList extends StatelessWidget {
198
220
return SubscriptionItem (subscription: subscription,
199
221
unreadCount: unreadCount,
200
222
showMutedUnreadBadge: showMutedUnreadBadge,
201
- showTopicListButtonInActionSheet: showTopicListButtonInActionSheet);
223
+ showTopicListButtonInActionSheet: showTopicListButtonInActionSheet,
224
+ onChannelSelect: onChannelSelect);
202
225
});
203
226
}
204
227
}
@@ -211,12 +234,14 @@ class SubscriptionItem extends StatelessWidget {
211
234
required this .unreadCount,
212
235
required this .showMutedUnreadBadge,
213
236
required this .showTopicListButtonInActionSheet,
237
+ required this .onChannelSelect,
214
238
});
215
239
216
240
final Subscription subscription;
217
241
final int unreadCount;
218
242
final bool showMutedUnreadBadge;
219
243
final bool showTopicListButtonInActionSheet;
244
+ final OnChannelSelectCallback onChannelSelect;
220
245
221
246
@override
222
247
Widget build (BuildContext context) {
@@ -229,11 +254,7 @@ class SubscriptionItem extends StatelessWidget {
229
254
// TODO(design) check if this is the right variable
230
255
color: designVariables.background,
231
256
child: InkWell (
232
- onTap: () {
233
- Navigator .push (context,
234
- MessageListPage .buildRoute (context: context,
235
- narrow: ChannelNarrow (subscription.streamId)));
236
- },
257
+ onTap: () => onChannelSelect (ChannelNarrow (subscription.streamId)),
237
258
onLongPress: () => showChannelActionSheet (context,
238
259
channelId: subscription.streamId,
239
260
showTopicListButton: showTopicListButtonInActionSheet),
0 commit comments