@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
5
5
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart' ;
6
6
import 'package:image_picker/image_picker.dart' ;
7
7
8
+ import '../api/exception.dart' ;
8
9
import '../api/model/model.dart' ;
9
10
import '../api/route/messages.dart' ;
10
11
import '../model/compose.dart' ;
@@ -716,7 +717,7 @@ class _SendButtonState extends State<_SendButton> {
716
717
|| widget.contentController.hasValidationErrors.value;
717
718
}
718
719
719
- void _send () {
720
+ void _send () async {
720
721
if (_hasValidationErrors) {
721
722
final zulipLocalizations = ZulipLocalizations .of (context);
722
723
List <String > validationErrorMessages = [
@@ -735,7 +736,23 @@ class _SendButtonState extends State<_SendButton> {
735
736
736
737
final store = PerAccountStoreWidget .of (context);
737
738
final content = widget.contentController.textNormalized;
738
- store.sendMessage (destination: widget.getDestination (), content: content);
739
+
740
+ try {
741
+ // TODO(#720) put input(s) and send button into a disabled "working on it"
742
+ // state (allowing input text to be selected for copying).
743
+ await store.sendMessage (destination: widget.getDestination (), content: content);
744
+ } on ApiRequestException catch (e) {
745
+ if (! mounted) return ;
746
+ final zulipLocalizations = ZulipLocalizations .of (context);
747
+ final message = switch (e) {
748
+ ZulipApiException () => zulipLocalizations.errorServerMessage (e.message),
749
+ _ => e.message,
750
+ };
751
+ showErrorDialog (context: context,
752
+ title: zulipLocalizations.errorMessageNotSent,
753
+ message: message);
754
+ return ;
755
+ }
739
756
740
757
widget.contentController.clear ();
741
758
}
0 commit comments