1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 04:49:21 +00:00

Improved send message form UI

This commit is contained in:
Pierre HUBERT 2019-04-25 20:22:53 +02:00
parent d07774c6d5
commit 05f7396c98

View File

@ -97,21 +97,24 @@ class _ConversationScreenState extends State<ConversationScreen> {
image: image,
),
);
// In case a message was already written in the input
_updatedText(_textEditingController.text);
}
/// Send a new text message
Future<void> _submitTextMessage(BuildContext context, String content) async {
_submitMessage(
if (await _submitMessage(
context,
NewConversationMessage(
conversationID: widget.conversationID,
message: content,
),
);
)) ==
SendMessageResult.SUCCESS) _clearSendMessageForm();
}
/// Submit a new message
Future<void> _submitMessage(
Future<SendMessageResult> _submitMessage(
BuildContext context, NewConversationMessage message) async {
//Send the message
_setSending(true);
@ -119,9 +122,7 @@ class _ConversationScreenState extends State<ConversationScreen> {
_setSending(false);
//Check the result of the operation
if (result == SendMessageResult.SUCCESS)
_clearSendMessageForm();
else
if (result != SendMessageResult.SUCCESS)
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text(
@ -132,6 +133,14 @@ class _ConversationScreenState extends State<ConversationScreen> {
duration: Duration(milliseconds: 500),
),
);
return result;
}
void _updatedText(String text) {
setState(() {
_isMessageValid = text.length > 4;
});
}
/// Clear send message form
@ -173,20 +182,20 @@ class _ConversationScreenState extends State<ConversationScreen> {
child: new IconButton(
icon: new Icon(
Icons.photo_camera,
color: Theme.of(context).accentColor,
color: _isSendingMessage
? Theme.of(context).disabledColor
: Theme.of(context).accentColor,
),
onPressed: () => _sendImage(context),
),
onPressed: () => _sendImage(context)),
),
// Message area
new Flexible(
child: new TextField(
enabled: !_isSendingMessage,
controller: _textEditingController,
onChanged: (String messageText) {
setState(() {
_isMessageValid = messageText.length > 4;
});
},
onChanged: _updatedText,
onSubmitted: _isMessageValid
? (s) => _submitTextMessage(context, s)
: null,