Skip to content

Commit fd72c44

Browse files
committed
(squash) move onChannelSelect default up to public widget
1 parent 9080b78 commit fd72c44

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

lib/widgets/subscription_list.dart

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class SubscriptionListPageBody extends StatefulWidget {
3131
// https://github.com/zulip/zulip-flutter/pull/1774#discussion_r2249032503
3232
final bool disableChannelActionSheet;
3333
final bool hideChannelsIfUserCantPost;
34+
35+
/// Callback to invoke when the user selects a channel from the list.
36+
///
37+
/// If null, the default behavior is to navigate to the channel feed.
3438
final OnChannelSelectCallback? onChannelSelect;
3539
// TODO(#412) add onTopicSelect
3640

@@ -82,6 +86,12 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
8286
});
8387
}
8488

89+
void _handleChannelSelect(ChannelNarrow narrow) {
90+
Navigator.push(context,
91+
MessageListPage.buildRoute(context: context,
92+
narrow: narrow));
93+
}
94+
8595
@override
8696
Widget build(BuildContext context) {
8797
// Design referenced from:
@@ -124,6 +134,7 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
124134
message: zulipLocalizations.channelsEmptyPlaceholder);
125135
}
126136

137+
final onChannelSelect = widget.onChannelSelect ?? _handleChannelSelect;
127138
return SafeArea(
128139
// Don't pad the bottom here; we want the list content to do that.
129140
//
@@ -144,15 +155,15 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
144155
unreadsModel: unreadsModel,
145156
subscriptions: pinned,
146157
disableChannelActionSheet: widget.disableChannelActionSheet,
147-
onChannelSelect: widget.onChannelSelect),
158+
onChannelSelect: onChannelSelect),
148159
],
149160
if (unpinned.isNotEmpty) ...[
150161
_SubscriptionListHeader(label: zulipLocalizations.unpinnedSubscriptionsLabel),
151162
_SubscriptionList(
152163
unreadsModel: unreadsModel,
153164
subscriptions: unpinned,
154165
disableChannelActionSheet: widget.disableChannelActionSheet,
155-
onChannelSelect: widget.onChannelSelect),
166+
onChannelSelect: onChannelSelect),
156167
],
157168

158169
// TODO(#188): add button leading to "All Streams" page with ability to subscribe
@@ -206,13 +217,13 @@ class _SubscriptionList extends StatelessWidget {
206217
required this.unreadsModel,
207218
required this.subscriptions,
208219
required this.disableChannelActionSheet,
209-
this.onChannelSelect,
220+
required this.onChannelSelect,
210221
});
211222

212223
final Unreads? unreadsModel;
213224
final List<Subscription> subscriptions;
214225
final bool disableChannelActionSheet;
215-
final OnChannelSelectCallback? onChannelSelect;
226+
final OnChannelSelectCallback onChannelSelect;
216227

217228
@override
218229
Widget build(BuildContext context) {
@@ -227,12 +238,7 @@ class _SubscriptionList extends StatelessWidget {
227238
unreadCount: unreadCount,
228239
showMutedUnreadBadge: showMutedUnreadBadge,
229240
disableChannelActionSheet: disableChannelActionSheet,
230-
onChannelSelect: onChannelSelect
231-
?? (narrow) {
232-
Navigator.push(context,
233-
MessageListPage.buildRoute(context: context,
234-
narrow: narrow));
235-
});
241+
onChannelSelect: onChannelSelect);
236242
});
237243
}
238244
}

0 commit comments

Comments
 (0)