mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Improved send message form UI
This commit is contained in:
parent
d07774c6d5
commit
05f7396c98
@ -97,21 +97,24 @@ class _ConversationScreenState extends State<ConversationScreen> {
|
|||||||
image: image,
|
image: image,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// In case a message was already written in the input
|
||||||
|
_updatedText(_textEditingController.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a new text message
|
/// Send a new text message
|
||||||
Future<void> _submitTextMessage(BuildContext context, String content) async {
|
Future<void> _submitTextMessage(BuildContext context, String content) async {
|
||||||
_submitMessage(
|
if (await _submitMessage(
|
||||||
context,
|
context,
|
||||||
NewConversationMessage(
|
NewConversationMessage(
|
||||||
conversationID: widget.conversationID,
|
conversationID: widget.conversationID,
|
||||||
message: content,
|
message: content,
|
||||||
),
|
)) ==
|
||||||
);
|
SendMessageResult.SUCCESS) _clearSendMessageForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Submit a new message
|
/// Submit a new message
|
||||||
Future<void> _submitMessage(
|
Future<SendMessageResult> _submitMessage(
|
||||||
BuildContext context, NewConversationMessage message) async {
|
BuildContext context, NewConversationMessage message) async {
|
||||||
//Send the message
|
//Send the message
|
||||||
_setSending(true);
|
_setSending(true);
|
||||||
@ -119,9 +122,7 @@ class _ConversationScreenState extends State<ConversationScreen> {
|
|||||||
_setSending(false);
|
_setSending(false);
|
||||||
|
|
||||||
//Check the result of the operation
|
//Check the result of the operation
|
||||||
if (result == SendMessageResult.SUCCESS)
|
if (result != SendMessageResult.SUCCESS)
|
||||||
_clearSendMessageForm();
|
|
||||||
else
|
|
||||||
Scaffold.of(context).showSnackBar(
|
Scaffold.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
@ -132,6 +133,14 @@ class _ConversationScreenState extends State<ConversationScreen> {
|
|||||||
duration: Duration(milliseconds: 500),
|
duration: Duration(milliseconds: 500),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _updatedText(String text) {
|
||||||
|
setState(() {
|
||||||
|
_isMessageValid = text.length > 4;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear send message form
|
/// Clear send message form
|
||||||
@ -171,22 +180,22 @@ class _ConversationScreenState extends State<ConversationScreen> {
|
|||||||
new Container(
|
new Container(
|
||||||
margin: new EdgeInsets.symmetric(horizontal: 4.0),
|
margin: new EdgeInsets.symmetric(horizontal: 4.0),
|
||||||
child: new IconButton(
|
child: new IconButton(
|
||||||
icon: new Icon(
|
icon: new Icon(
|
||||||
Icons.photo_camera,
|
Icons.photo_camera,
|
||||||
color: Theme.of(context).accentColor,
|
color: _isSendingMessage
|
||||||
),
|
? Theme.of(context).disabledColor
|
||||||
onPressed: () => _sendImage(context)),
|
: Theme.of(context).accentColor,
|
||||||
|
),
|
||||||
|
onPressed: () => _sendImage(context),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// Message area
|
// Message area
|
||||||
new Flexible(
|
new Flexible(
|
||||||
child: new TextField(
|
child: new TextField(
|
||||||
|
enabled: !_isSendingMessage,
|
||||||
controller: _textEditingController,
|
controller: _textEditingController,
|
||||||
onChanged: (String messageText) {
|
onChanged: _updatedText,
|
||||||
setState(() {
|
|
||||||
_isMessageValid = messageText.length > 4;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onSubmitted: _isMessageValid
|
onSubmitted: _isMessageValid
|
||||||
? (s) => _submitTextMessage(context, s)
|
? (s) => _submitTextMessage(context, s)
|
||||||
: null,
|
: null,
|
||||||
|
Loading…
Reference in New Issue
Block a user