@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
55import 'package:flutter_gen/gen_l10n/zulip_localizations.dart' ;
66import 'package:image_picker/image_picker.dart' ;
77
8+ import '../api/exception.dart' ;
89import '../api/model/model.dart' ;
910import '../api/route/messages.dart' ;
1011import '../model/compose.dart' ;
@@ -716,7 +717,7 @@ class _SendButtonState extends State<_SendButton> {
716717 || widget.contentController.hasValidationErrors.value;
717718 }
718719
719- void _send () {
720+ void _send () async {
720721 if (_hasValidationErrors) {
721722 final zulipLocalizations = ZulipLocalizations .of (context);
722723 List <String > validationErrorMessages = [
@@ -735,9 +736,26 @@ class _SendButtonState extends State<_SendButton> {
735736
736737 final store = PerAccountStoreWidget .of (context);
737738 final content = widget.contentController.textNormalized;
738- store.sendMessage (destination: widget.getDestination (), content: content);
739739
740740 widget.contentController.clear ();
741+
742+ try {
743+ // TODO(#720) clear content input only on success response;
744+ // while waiting, put input(s) and send button into a disabled
745+ // "working on it" state (letting input text be selected for copying).
746+ await store.sendMessage (destination: widget.getDestination (), content: content);
747+ } on ApiRequestException catch (e) {
748+ if (! mounted) return ;
749+ final zulipLocalizations = ZulipLocalizations .of (context);
750+ final message = switch (e) {
751+ ZulipApiException () => zulipLocalizations.errorServerMessage (e.message),
752+ _ => e.message,
753+ };
754+ showErrorDialog (context: context,
755+ title: zulipLocalizations.errorMessageNotSent,
756+ message: message);
757+ return ;
758+ }
741759 }
742760
743761 @override
0 commit comments