Skip to content

Commit 7eaf946

Browse files
committed
compose [nfc]: Pass whole controller down (1/6); _StreamContentInput
For zulip#720, we'd like to add fields to ComposeBoxController and use them in a bunch of widgets deeper in the compose box, like the various buttons, without having to add references to them in those widgets' constructors. With that in mind, pass the whole controller down, and the widgets can access the fields directly from it. As suggested by Greg: zulip#1090 (comment)
1 parent 5b10ba6 commit 7eaf946

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

lib/widgets/compose_box.dart

+12-21
Original file line numberDiff line numberDiff line change
@@ -442,17 +442,10 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve
442442

443443
/// The content input for _StreamComposeBox.
444444
class _StreamContentInput extends StatefulWidget {
445-
const _StreamContentInput({
446-
required this.narrow,
447-
required this.controller,
448-
required this.topicController,
449-
required this.focusNode,
450-
});
445+
const _StreamContentInput({required this.narrow, required this.controller});
451446

452447
final ChannelNarrow narrow;
453-
final ComposeContentController controller;
454-
final ComposeTopicController topicController;
455-
final FocusNode focusNode;
448+
final StreamComposeBoxController controller;
456449

457450
@override
458451
State<_StreamContentInput> createState() => _StreamContentInputState();
@@ -463,29 +456,29 @@ class _StreamContentInputState extends State<_StreamContentInput> {
463456

464457
void _topicChanged() {
465458
setState(() {
466-
_topicTextNormalized = widget.topicController.textNormalized;
459+
_topicTextNormalized = widget.controller.topic.textNormalized;
467460
});
468461
}
469462

470463
@override
471464
void initState() {
472465
super.initState();
473-
_topicTextNormalized = widget.topicController.textNormalized;
474-
widget.topicController.addListener(_topicChanged);
466+
_topicTextNormalized = widget.controller.topic.textNormalized;
467+
widget.controller.topic.addListener(_topicChanged);
475468
}
476469

477470
@override
478471
void didUpdateWidget(covariant _StreamContentInput oldWidget) {
479472
super.didUpdateWidget(oldWidget);
480-
if (widget.topicController != oldWidget.topicController) {
481-
oldWidget.topicController.removeListener(_topicChanged);
482-
widget.topicController.addListener(_topicChanged);
473+
if (widget.controller.topic != oldWidget.controller.topic) {
474+
oldWidget.controller.topic.removeListener(_topicChanged);
475+
widget.controller.topic.addListener(_topicChanged);
483476
}
484477
}
485478

486479
@override
487480
void dispose() {
488-
widget.topicController.removeListener(_topicChanged);
481+
widget.controller.topic.removeListener(_topicChanged);
489482
super.dispose();
490483
}
491484

@@ -498,8 +491,8 @@ class _StreamContentInputState extends State<_StreamContentInput> {
498491
return _ContentInput(
499492
narrow: widget.narrow,
500493
destination: TopicNarrow(widget.narrow.streamId, _topicTextNormalized),
501-
controller: widget.controller,
502-
focusNode: widget.focusNode,
494+
controller: widget.controller.content,
495+
focusNode: widget.controller.contentFocusNode,
503496
hintText: zulipLocalizations.composeBoxChannelContentHint(streamName, _topicTextNormalized));
504497
}
505498
}
@@ -1156,9 +1149,7 @@ class _StreamComposeBoxBody extends _ComposeBoxBody {
11561149

11571150
@override Widget contentInput() => _StreamContentInput(
11581151
narrow: narrow,
1159-
topicController: controller.topic,
1160-
controller: controller.content,
1161-
focusNode: controller.contentFocusNode,
1152+
controller: controller,
11621153
);
11631154

11641155
@override Widget sendButton() => _SendButton(

0 commit comments

Comments
 (0)