Skip to content

Commit 84c812e

Browse files
committed
compose [nfc]: Simplify choose-body logic by switching on controller
1 parent bac2ce9 commit 84c812e

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

lib/widgets/compose_box.dart

+11-18
Original file line numberDiff line numberDiff line change
@@ -1356,24 +1356,17 @@ class _ComposeBoxState extends State<ComposeBox> implements ComposeBoxState {
13561356
// ZulipLocalizations.of(context).errorSendMessageTimeout);
13571357
// }
13581358
final narrow = widget.narrow;
1359-
switch (narrow) {
1360-
case ChannelNarrow():
1361-
assert(_controller is StreamComposeBoxController);
1362-
body = _StreamComposeBoxBody(controller: (_controller as StreamComposeBoxController),
1363-
narrow: narrow);
1364-
case TopicNarrow():
1365-
assert(_controller is FixedDestinationComposeBoxController);
1366-
body = _FixedDestinationComposeBoxBody(controller: (_controller as FixedDestinationComposeBoxController),
1367-
narrow: narrow);
1368-
case DmNarrow():
1369-
assert(_controller is FixedDestinationComposeBoxController);
1370-
body = _FixedDestinationComposeBoxBody(controller: (_controller as FixedDestinationComposeBoxController),
1371-
narrow: narrow);
1372-
case CombinedFeedNarrow():
1373-
case MentionsNarrow():
1374-
case StarredMessagesNarrow():
1375-
assert(false);
1376-
body = null;
1359+
switch (_controller) {
1360+
case StreamComposeBoxController(): {
1361+
assert(narrow is ChannelNarrow);
1362+
body = _StreamComposeBoxBody(controller: _controller,
1363+
narrow: (narrow as ChannelNarrow));
1364+
}
1365+
case FixedDestinationComposeBoxController(): {
1366+
assert(narrow is SendableNarrow);
1367+
body = _FixedDestinationComposeBoxBody(controller: _controller,
1368+
narrow: (narrow as SendableNarrow));
1369+
}
13771370
}
13781371
}
13791372

0 commit comments

Comments
 (0)