Skip to content

Commit 55538bf

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 55538bf

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

lib/widgets/subscription_list.dart

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

16+
typedef OnChannelSelectCallback = void Function(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;
30+
// TODO(#412) add onTopicSelect
2631

2732
@override
2833
State<SubscriptionListPageBody> createState() => _SubscriptionListPageBodyState();
@@ -122,14 +127,16 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
122127
_SubscriptionList(
123128
unreadsModel: unreadsModel,
124129
subscriptions: pinned,
125-
disableChannelActionSheet: widget.disableChannelActionSheet),
130+
disableChannelActionSheet: widget.disableChannelActionSheet,
131+
onChannelSelect: widget.onChannelSelect),
126132
],
127133
if (unpinned.isNotEmpty) ...[
128134
_SubscriptionListHeader(label: zulipLocalizations.unpinnedSubscriptionsLabel),
129135
_SubscriptionList(
130136
unreadsModel: unreadsModel,
131137
subscriptions: unpinned,
132-
disableChannelActionSheet: widget.disableChannelActionSheet),
138+
disableChannelActionSheet: widget.disableChannelActionSheet,
139+
onChannelSelect: widget.onChannelSelect),
133140
],
134141

135142
// TODO(#188): add button leading to "All Streams" page with ability to subscribe
@@ -180,11 +187,13 @@ class _SubscriptionList extends StatelessWidget {
180187
required this.unreadsModel,
181188
required this.subscriptions,
182189
required this.disableChannelActionSheet,
190+
this.onChannelSelect,
183191
});
184192

185193
final Unreads? unreadsModel;
186194
final List<Subscription> subscriptions;
187195
final bool disableChannelActionSheet;
196+
final OnChannelSelectCallback? onChannelSelect;
188197

189198
@override
190199
Widget build(BuildContext context) {
@@ -198,7 +207,13 @@ class _SubscriptionList extends StatelessWidget {
198207
return SubscriptionItem(subscription: subscription,
199208
unreadCount: unreadCount,
200209
showMutedUnreadBadge: showMutedUnreadBadge,
201-
disableChannelActionSheet: disableChannelActionSheet);
210+
disableChannelActionSheet: disableChannelActionSheet,
211+
onChannelSelect: onChannelSelect
212+
?? (narrow) {
213+
Navigator.push(context,
214+
MessageListPage.buildRoute(context: context,
215+
narrow: narrow));
216+
});
202217
});
203218
}
204219
}
@@ -211,12 +226,14 @@ class SubscriptionItem extends StatelessWidget {
211226
required this.unreadCount,
212227
required this.showMutedUnreadBadge,
213228
required this.disableChannelActionSheet,
229+
required this.onChannelSelect,
214230
});
215231

216232
final Subscription subscription;
217233
final int unreadCount;
218234
final bool showMutedUnreadBadge;
219235
final bool disableChannelActionSheet;
236+
final OnChannelSelectCallback onChannelSelect;
220237

221238
@override
222239
Widget build(BuildContext context) {
@@ -229,11 +246,7 @@ class SubscriptionItem extends StatelessWidget {
229246
// TODO(design) check if this is the right variable
230247
color: designVariables.background,
231248
child: InkWell(
232-
onTap: () {
233-
Navigator.push(context,
234-
MessageListPage.buildRoute(context: context,
235-
narrow: ChannelNarrow(subscription.streamId)));
236-
},
249+
onTap: () => onChannelSelect(ChannelNarrow(subscription.streamId)),
237250
onLongPress: !disableChannelActionSheet
238251
? () => showChannelActionSheet(context, channelId: subscription.streamId)
239252
: null,

0 commit comments

Comments
 (0)