@@ -557,23 +557,22 @@ class _AttachFromCameraButton extends _AttachUploadsButton {
557
557
}
558
558
}
559
559
560
- /// The send button for _StreamComposeBox.
561
- class _StreamSendButton extends StatefulWidget {
562
- const _StreamSendButton ({
563
- required this .narrow,
560
+ class _SendButton extends StatefulWidget {
561
+ const _SendButton ({
564
562
required this .topicController,
565
563
required this .contentController,
564
+ required this .getDestination,
566
565
});
567
566
568
- final StreamNarrow narrow;
569
- final ComposeTopicController topicController;
567
+ final ComposeTopicController ? topicController;
570
568
final ComposeContentController contentController;
569
+ final MessageDestination Function () getDestination;
571
570
572
571
@override
573
- State <_StreamSendButton > createState () => _StreamSendButtonState ();
572
+ State <_SendButton > createState () => _SendButtonState ();
574
573
}
575
574
576
- class _StreamSendButtonState extends State <_StreamSendButton > {
575
+ class _SendButtonState extends State <_SendButton > {
577
576
_hasErrorsChanged () {
578
577
setState (() {
579
578
// Update disabled/non-disabled state
@@ -583,16 +582,16 @@ class _StreamSendButtonState extends State<_StreamSendButton> {
583
582
@override
584
583
void initState () {
585
584
super .initState ();
586
- widget.topicController.hasValidationErrors.addListener (_hasErrorsChanged);
585
+ widget.topicController? .hasValidationErrors.addListener (_hasErrorsChanged);
587
586
widget.contentController.hasValidationErrors.addListener (_hasErrorsChanged);
588
587
}
589
588
590
589
@override
591
- void didUpdateWidget (covariant _StreamSendButton oldWidget) {
590
+ void didUpdateWidget (covariant _SendButton oldWidget) {
592
591
super .didUpdateWidget (oldWidget);
593
592
if (widget.topicController != oldWidget.topicController) {
594
- oldWidget.topicController.hasValidationErrors.removeListener (_hasErrorsChanged);
595
- widget.topicController.hasValidationErrors.addListener (_hasErrorsChanged);
593
+ oldWidget.topicController? .hasValidationErrors.removeListener (_hasErrorsChanged);
594
+ widget.topicController? .hasValidationErrors.addListener (_hasErrorsChanged);
596
595
}
597
596
if (widget.contentController != oldWidget.contentController) {
598
597
oldWidget.contentController.hasValidationErrors.removeListener (_hasErrorsChanged);
@@ -602,20 +601,20 @@ class _StreamSendButtonState extends State<_StreamSendButton> {
602
601
603
602
@override
604
603
void dispose () {
605
- widget.topicController.hasValidationErrors.removeListener (_hasErrorsChanged);
604
+ widget.topicController? .hasValidationErrors.removeListener (_hasErrorsChanged);
606
605
widget.contentController.hasValidationErrors.removeListener (_hasErrorsChanged);
607
606
super .dispose ();
608
607
}
609
608
610
609
bool get _hasValidationErrors {
611
- return widget.topicController.hasValidationErrors.value
610
+ return ( widget.topicController? .hasValidationErrors.value ?? false )
612
611
|| widget.contentController.hasValidationErrors.value;
613
612
}
614
613
615
614
void _send () {
616
615
if (_hasValidationErrors) {
617
616
List <String > validationErrorMessages = [
618
- for (final error in widget.topicController.validationErrors)
617
+ for (final error in widget.topicController? .validationErrors ?? const [] )
619
618
error.message (),
620
619
for (final error in widget.contentController.validationErrors)
621
620
error.message (),
@@ -628,10 +627,8 @@ class _StreamSendButtonState extends State<_StreamSendButton> {
628
627
}
629
628
630
629
final store = PerAccountStoreWidget .of (context);
631
- final destination = StreamDestination (
632
- widget.narrow.streamId, widget.topicController.textNormalized);
633
630
final content = widget.contentController.textNormalized;
634
- store.sendMessage (destination: destination , content: content);
631
+ store.sendMessage (destination: widget. getDestination () , content: content);
635
632
636
633
widget.contentController.clear ();
637
634
}
@@ -743,10 +740,11 @@ class _StreamComposeBoxState extends State<_StreamComposeBox> {
743
740
focusNode: _contentFocusNode),
744
741
]))),
745
742
const SizedBox (width: 8 ),
746
- _StreamSendButton (
747
- narrow: widget.narrow,
743
+ _SendButton (
748
744
topicController: _topicController,
749
745
contentController: _contentController,
746
+ getDestination: () => StreamDestination (
747
+ widget.narrow.streamId, _topicController.textNormalized),
750
748
),
751
749
]),
752
750
Theme (
0 commit comments