@@ -867,14 +867,9 @@ class _AttachFromCameraButton extends _AttachUploadsButton {
867
867
}
868
868
869
869
class _SendButton extends StatefulWidget {
870
- const _SendButton ({
871
- required this .topicController,
872
- required this .contentController,
873
- required this .getDestination,
874
- });
870
+ const _SendButton ({required this .controller, required this .getDestination});
875
871
876
- final ComposeTopicController ? topicController;
877
- final ComposeContentController contentController;
872
+ final ComposeBoxController controller;
878
873
final MessageDestination Function () getDestination;
879
874
880
875
@override
@@ -891,43 +886,62 @@ class _SendButtonState extends State<_SendButton> {
891
886
@override
892
887
void initState () {
893
888
super .initState ();
894
- widget.topicController? .hasValidationErrors.addListener (_hasErrorsChanged);
895
- widget.contentController.hasValidationErrors.addListener (_hasErrorsChanged);
889
+ final controller = widget.controller;
890
+ if (controller is StreamComposeBoxController ) {
891
+ controller.topic.hasValidationErrors.addListener (_hasErrorsChanged);
892
+ }
893
+ controller.content.hasValidationErrors.addListener (_hasErrorsChanged);
896
894
}
897
895
898
896
@override
899
897
void didUpdateWidget (covariant _SendButton oldWidget) {
900
898
super .didUpdateWidget (oldWidget);
901
- if (widget.topicController != oldWidget.topicController) {
902
- oldWidget.topicController? .hasValidationErrors.removeListener (_hasErrorsChanged);
903
- widget.topicController? .hasValidationErrors.addListener (_hasErrorsChanged);
899
+
900
+ final controller = widget.controller;
901
+ final oldController = oldWidget.controller;
902
+ if (controller == oldController) return ;
903
+
904
+ if (oldController is StreamComposeBoxController ) {
905
+ oldController.topic.hasValidationErrors.removeListener (_hasErrorsChanged);
904
906
}
905
- if (widget.contentController != oldWidget.contentController) {
906
- oldWidget.contentController.hasValidationErrors.removeListener (_hasErrorsChanged);
907
- widget.contentController.hasValidationErrors.addListener (_hasErrorsChanged);
907
+ if (controller is StreamComposeBoxController ) {
908
+ controller.topic.hasValidationErrors.addListener (_hasErrorsChanged);
908
909
}
910
+ oldController.content.hasValidationErrors.removeListener (_hasErrorsChanged);
911
+ controller.content.hasValidationErrors.addListener (_hasErrorsChanged);
909
912
}
910
913
911
914
@override
912
915
void dispose () {
913
- widget.topicController? .hasValidationErrors.removeListener (_hasErrorsChanged);
914
- widget.contentController.hasValidationErrors.removeListener (_hasErrorsChanged);
916
+ final controller = widget.controller;
917
+ if (controller is StreamComposeBoxController ) {
918
+ controller.topic.hasValidationErrors.removeListener (_hasErrorsChanged);
919
+ }
920
+ controller.content.hasValidationErrors.removeListener (_hasErrorsChanged);
915
921
super .dispose ();
916
922
}
917
923
918
924
bool get _hasValidationErrors {
919
- return (widget.topicController? .hasValidationErrors.value ?? false )
920
- || widget.contentController.hasValidationErrors.value;
925
+ bool result = false ;
926
+ final controller = widget.controller;
927
+ if (controller is StreamComposeBoxController ) {
928
+ result = controller.topic.hasValidationErrors.value;
929
+ }
930
+ result | = controller.content.hasValidationErrors.value;
931
+ return result;
921
932
}
922
933
923
934
void _send () async {
935
+ final controller = widget.controller;
936
+
924
937
if (_hasValidationErrors) {
925
938
final zulipLocalizations = ZulipLocalizations .of (context);
926
939
List <String > validationErrorMessages = [
927
- for (final error in widget.topicController? .validationErrors
928
- ?? const < TopicValidationError > [])
940
+ for (final error in (controller is StreamComposeBoxController
941
+ ? controller.topic.validationErrors
942
+ : const < TopicValidationError > []))
929
943
error.message (zulipLocalizations),
930
- for (final error in widget.contentController .validationErrors)
944
+ for (final error in controller.content .validationErrors)
931
945
error.message (zulipLocalizations),
932
946
];
933
947
showErrorDialog (
@@ -938,9 +952,9 @@ class _SendButtonState extends State<_SendButton> {
938
952
}
939
953
940
954
final store = PerAccountStoreWidget .of (context);
941
- final content = widget.contentController .textNormalized;
955
+ final content = controller.content .textNormalized;
942
956
943
- widget.contentController .clear ();
957
+ controller.content .clear ();
944
958
// The following `stoppedComposing` call is currently redundant,
945
959
// because clearing input sends a "typing stopped" notice.
946
960
// It will be necessary once we resolve #720.
@@ -1137,8 +1151,7 @@ class _StreamComposeBoxBody extends _ComposeBoxBody {
1137
1151
);
1138
1152
1139
1153
@override Widget sendButton () => _SendButton (
1140
- topicController: controller.topic,
1141
- contentController: controller.content,
1154
+ controller: controller,
1142
1155
getDestination: () => StreamDestination (
1143
1156
narrow.streamId, controller.topic.textNormalized),
1144
1157
);
@@ -1161,8 +1174,7 @@ class _FixedDestinationComposeBoxBody extends _ComposeBoxBody {
1161
1174
);
1162
1175
1163
1176
@override Widget sendButton () => _SendButton (
1164
- topicController: null ,
1165
- contentController: controller.content,
1177
+ controller: controller,
1166
1178
getDestination: () => narrow.destination,
1167
1179
);
1168
1180
}
0 commit comments