@@ -574,67 +574,49 @@ class _StreamSendButton extends StatefulWidget {
574
574
}
575
575
576
576
class _StreamSendButtonState extends State <_StreamSendButton > {
577
- late List <TopicValidationError > _topicValidationErrors;
578
- late List <ContentValidationError > _contentValidationErrors;
579
-
580
- _topicChanged () {
581
- final oldIsEmpty = _topicValidationErrors.isEmpty;
582
- final newErrors = widget.topicController.validationErrors;
583
- final newIsEmpty = newErrors.isEmpty;
584
- _topicValidationErrors = newErrors;
585
- if (oldIsEmpty != newIsEmpty) {
586
- setState (() {
587
- // Update disabled/non-disabled state
588
- });
589
- }
590
- }
591
-
592
- _contentChanged () {
593
- final oldIsEmpty = _contentValidationErrors.isEmpty;
594
- final newErrors = widget.contentController.validationErrors;
595
- final newIsEmpty = newErrors.isEmpty;
596
- _contentValidationErrors = newErrors;
597
- if (oldIsEmpty != newIsEmpty) {
598
- setState (() {
599
- // Update disabled/non-disabled state
600
- });
601
- }
577
+ _hasErrorsChanged () {
578
+ setState (() {
579
+ // Update disabled/non-disabled state
580
+ });
602
581
}
603
582
604
583
@override
605
584
void initState () {
606
585
super .initState ();
607
- _topicValidationErrors = widget.topicController.validationErrors;
608
- _contentValidationErrors = widget.contentController.validationErrors;
609
- widget.topicController.addListener (_topicChanged);
610
- widget.contentController.addListener (_contentChanged);
586
+ widget.topicController.hasValidationErrors.addListener (_hasErrorsChanged);
587
+ widget.contentController.hasValidationErrors.addListener (_hasErrorsChanged);
611
588
}
612
589
613
590
@override
614
591
void didUpdateWidget (covariant _StreamSendButton oldWidget) {
615
592
super .didUpdateWidget (oldWidget);
616
593
if (widget.topicController != oldWidget.topicController) {
617
- oldWidget.topicController.removeListener (_topicChanged );
618
- widget.topicController.addListener (_topicChanged );
594
+ oldWidget.topicController.hasValidationErrors. removeListener (_hasErrorsChanged );
595
+ widget.topicController.hasValidationErrors. addListener (_hasErrorsChanged );
619
596
}
620
597
if (widget.contentController != oldWidget.contentController) {
621
- oldWidget.contentController.removeListener (_contentChanged );
622
- widget.contentController.addListener (_contentChanged );
598
+ oldWidget.contentController.hasValidationErrors. removeListener (_hasErrorsChanged );
599
+ widget.contentController.hasValidationErrors. addListener (_hasErrorsChanged );
623
600
}
624
601
}
625
602
626
603
@override
627
604
void dispose () {
628
- widget.topicController.removeListener (_topicChanged );
629
- widget.contentController.removeListener (_contentChanged );
605
+ widget.topicController.hasValidationErrors. removeListener (_hasErrorsChanged );
606
+ widget.contentController.hasValidationErrors. removeListener (_hasErrorsChanged );
630
607
super .dispose ();
631
608
}
632
609
610
+ bool get _hasValidationErrors {
611
+ return widget.topicController.hasValidationErrors.value
612
+ || widget.contentController.hasValidationErrors.value;
613
+ }
614
+
633
615
void _showSendFailedDialog (BuildContext context) {
634
616
List <String > validationErrorMessages = [
635
- for (final error in _topicValidationErrors )
617
+ for (final error in widget.topicController.validationErrors )
636
618
error.message (),
637
- for (final error in _contentValidationErrors )
619
+ for (final error in widget.contentController.validationErrors )
638
620
error.message (),
639
621
];
640
622
@@ -645,7 +627,7 @@ class _StreamSendButtonState extends State<_StreamSendButton> {
645
627
}
646
628
647
629
void _handleSendPressed (BuildContext context) {
648
- if (_topicValidationErrors.isNotEmpty || _contentValidationErrors.isNotEmpty ) {
630
+ if (_hasValidationErrors ) {
649
631
_showSendFailedDialog (context);
650
632
return ;
651
633
}
@@ -663,7 +645,7 @@ class _StreamSendButtonState extends State<_StreamSendButton> {
663
645
Widget build (BuildContext context) {
664
646
ColorScheme colorScheme = Theme .of (context).colorScheme;
665
647
666
- bool disabled = _topicValidationErrors.isNotEmpty || _contentValidationErrors.isNotEmpty ;
648
+ final disabled = _hasValidationErrors ;
667
649
668
650
// Copy FilledButton defaults (_FilledButtonDefaultsM3.backgroundColor)
669
651
final backgroundColor = disabled
0 commit comments