Skip to content

Commit 6b38b34

Browse files
subscription_list [nfc]: Allow onChannelSelect callback, notifying the selected channel
This will be used soon to provide specific behaviour when selecting a channel, where if specified it will replace the default behaviour of routing to the message list page of the selected channel narrow.
1 parent a02341b commit 6b38b34

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

lib/widgets/subscription_list.dart

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ import 'text.dart';
1313
import 'theme.dart';
1414
import 'unread_count_badge.dart';
1515

16+
typedef OnChannelSelectCallback = void Function(BuildContext context, ChannelNarrow narrow);
17+
1618
/// Scrollable listing of subscribed streams.
1719
class SubscriptionListPageBody extends StatefulWidget {
1820
const SubscriptionListPageBody({
1921
super.key,
2022
this.disableChannelActionSheet = false,
2123
this.hideChannelsIfUserCantPost = false,
24+
this.onChannelSelect,
2225
});
2326

2427
final bool disableChannelActionSheet;
2528
final bool hideChannelsIfUserCantPost;
29+
final OnChannelSelectCallback? onChannelSelect;
2630

2731
@override
2832
State<SubscriptionListPageBody> createState() => _SubscriptionListPageBodyState();
@@ -122,14 +126,16 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
122126
_SubscriptionList(
123127
unreadsModel: unreadsModel,
124128
subscriptions: pinned,
125-
disableChannelActionSheet: widget.disableChannelActionSheet),
129+
disableChannelActionSheet: widget.disableChannelActionSheet,
130+
onChannelSelect: widget.onChannelSelect),
126131
],
127132
if (unpinned.isNotEmpty) ...[
128133
_SubscriptionListHeader(label: zulipLocalizations.unpinnedSubscriptionsLabel),
129134
_SubscriptionList(
130135
unreadsModel: unreadsModel,
131136
subscriptions: unpinned,
132-
disableChannelActionSheet: widget.disableChannelActionSheet),
137+
disableChannelActionSheet: widget.disableChannelActionSheet,
138+
onChannelSelect: widget.onChannelSelect),
133139
],
134140

135141
// TODO(#188): add button leading to "All Streams" page with ability to subscribe
@@ -180,11 +186,13 @@ class _SubscriptionList extends StatelessWidget {
180186
required this.unreadsModel,
181187
required this.subscriptions,
182188
required this.disableChannelActionSheet,
189+
this.onChannelSelect,
183190
});
184191

185192
final Unreads? unreadsModel;
186193
final List<Subscription> subscriptions;
187194
final bool disableChannelActionSheet;
195+
final OnChannelSelectCallback? onChannelSelect;
188196

189197
@override
190198
Widget build(BuildContext context) {
@@ -198,7 +206,13 @@ class _SubscriptionList extends StatelessWidget {
198206
return SubscriptionItem(subscription: subscription,
199207
unreadCount: unreadCount,
200208
showMutedUnreadBadge: showMutedUnreadBadge,
201-
disableChannelActionSheet: disableChannelActionSheet);
209+
disableChannelActionSheet: disableChannelActionSheet,
210+
onChannelSelect: onChannelSelect
211+
?? (context, narrow) {
212+
Navigator.push(context,
213+
MessageListPage.buildRoute(context: context,
214+
narrow: narrow));
215+
});
202216
});
203217
}
204218
}
@@ -211,12 +225,14 @@ class SubscriptionItem extends StatelessWidget {
211225
required this.unreadCount,
212226
required this.showMutedUnreadBadge,
213227
required this.disableChannelActionSheet,
228+
required this.onChannelSelect,
214229
});
215230

216231
final Subscription subscription;
217232
final int unreadCount;
218233
final bool showMutedUnreadBadge;
219234
final bool disableChannelActionSheet;
235+
final OnChannelSelectCallback onChannelSelect;
220236

221237
@override
222238
Widget build(BuildContext context) {
@@ -229,11 +245,7 @@ class SubscriptionItem extends StatelessWidget {
229245
// TODO(design) check if this is the right variable
230246
color: designVariables.background,
231247
child: InkWell(
232-
onTap: () {
233-
Navigator.push(context,
234-
MessageListPage.buildRoute(context: context,
235-
narrow: ChannelNarrow(subscription.streamId)));
236-
},
248+
onTap: () => onChannelSelect(context, ChannelNarrow(subscription.streamId)),
237249
onLongPress: !disableChannelActionSheet
238250
? () => showChannelActionSheet(context, channelId: subscription.streamId)
239251
: null,

0 commit comments

Comments
 (0)