Skip to content

Commit a85f742

Browse files
committed
compose [nfc]: Tighten send button a bit
In particular because these methods are on a State, not a StatelessWidget, they have direct access to a BuildContext and so we don't need to pass one around.
1 parent 3876c0a commit a85f742

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

lib/widgets/compose_box.dart

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -612,23 +612,18 @@ class _StreamSendButtonState extends State<_StreamSendButton> {
612612
|| widget.contentController.hasValidationErrors.value;
613613
}
614614

615-
void _showSendFailedDialog(BuildContext context) {
616-
List<String> validationErrorMessages = [
617-
for (final error in widget.topicController.validationErrors)
618-
error.message(),
619-
for (final error in widget.contentController.validationErrors)
620-
error.message(),
621-
];
622-
623-
return showErrorDialog(
624-
context: context,
625-
title: 'Message not sent',
626-
message: validationErrorMessages.join('\n\n'));
627-
}
628-
629-
void _handleSendPressed(BuildContext context) {
615+
void _send() {
630616
if (_hasValidationErrors) {
631-
_showSendFailedDialog(context);
617+
List<String> validationErrorMessages = [
618+
for (final error in widget.topicController.validationErrors)
619+
error.message(),
620+
for (final error in widget.contentController.validationErrors)
621+
error.message(),
622+
];
623+
showErrorDialog(
624+
context: context,
625+
title: 'Message not sent',
626+
message: validationErrorMessages.join('\n\n'));
632627
return;
633628
}
634629

@@ -643,9 +638,8 @@ class _StreamSendButtonState extends State<_StreamSendButton> {
643638

644639
@override
645640
Widget build(BuildContext context) {
646-
ColorScheme colorScheme = Theme.of(context).colorScheme;
647-
648641
final disabled = _hasValidationErrors;
642+
final colorScheme = Theme.of(context).colorScheme;
649643

650644
// Copy FilledButton defaults (_FilledButtonDefaultsM3.backgroundColor)
651645
final backgroundColor = disabled
@@ -672,7 +666,7 @@ class _StreamSendButtonState extends State<_StreamSendButton> {
672666

673667
color: foregroundColor,
674668
icon: const Icon(Icons.send),
675-
onPressed: () => _handleSendPressed(context)));
669+
onPressed: _send));
676670
}
677671
}
678672

0 commit comments

Comments
 (0)