mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Can send images in conversations
This commit is contained in:
		@@ -86,15 +86,36 @@ class _ConversationScreenState extends State<ConversationScreen> {
 | 
			
		||||
  /// Pick and send an image
 | 
			
		||||
  Future<void> _sendImage(BuildContext context) async {
 | 
			
		||||
    final image = await pickImage(context);
 | 
			
		||||
 | 
			
		||||
    if (image == null) return null;
 | 
			
		||||
 | 
			
		||||
    _submitMessage(
 | 
			
		||||
      context,
 | 
			
		||||
      NewConversationMessage(
 | 
			
		||||
        conversationID: widget.conversationID,
 | 
			
		||||
        message: null,
 | 
			
		||||
        image: image,
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Send a new message
 | 
			
		||||
  Future<void> _submitMessage(BuildContext context, String content) async {
 | 
			
		||||
  /// Send a new text message
 | 
			
		||||
  Future<void> _submitTextMessage(BuildContext context, String content) async {
 | 
			
		||||
    _submitMessage(
 | 
			
		||||
      context,
 | 
			
		||||
      NewConversationMessage(
 | 
			
		||||
        conversationID: widget.conversationID,
 | 
			
		||||
        message: content,
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Submit a new message
 | 
			
		||||
  Future<void> _submitMessage(
 | 
			
		||||
      BuildContext context, NewConversationMessage message) async {
 | 
			
		||||
    //Send the message
 | 
			
		||||
    _setSending(true);
 | 
			
		||||
    final result = await _conversationsHelper.sendMessage(
 | 
			
		||||
        NewConversationMessage(
 | 
			
		||||
            conversationID: widget.conversationID, message: content));
 | 
			
		||||
    final result = await _conversationsHelper.sendMessage(message);
 | 
			
		||||
    _setSending(false);
 | 
			
		||||
 | 
			
		||||
    //Check the result of the operation
 | 
			
		||||
@@ -148,14 +169,14 @@ class _ConversationScreenState extends State<ConversationScreen> {
 | 
			
		||||
        children: <Widget>[
 | 
			
		||||
          // Image area
 | 
			
		||||
          new Container(
 | 
			
		||||
              margin: new EdgeInsets.symmetric(horizontal: 4.0),
 | 
			
		||||
              child: new IconButton(
 | 
			
		||||
                  icon: new Icon(
 | 
			
		||||
                    Icons.photo_camera,
 | 
			
		||||
                    color: Theme.of(context).accentColor,
 | 
			
		||||
                  ),
 | 
			
		||||
                  onPressed: () => _sendImage(context)),
 | 
			
		||||
            ),
 | 
			
		||||
            margin: new EdgeInsets.symmetric(horizontal: 4.0),
 | 
			
		||||
            child: new IconButton(
 | 
			
		||||
                icon: new Icon(
 | 
			
		||||
                  Icons.photo_camera,
 | 
			
		||||
                  color: Theme.of(context).accentColor,
 | 
			
		||||
                ),
 | 
			
		||||
                onPressed: () => _sendImage(context)),
 | 
			
		||||
          ),
 | 
			
		||||
 | 
			
		||||
          // Message area
 | 
			
		||||
          new Flexible(
 | 
			
		||||
@@ -166,8 +187,9 @@ class _ConversationScreenState extends State<ConversationScreen> {
 | 
			
		||||
                  _isMessageValid = messageText.length > 4;
 | 
			
		||||
                });
 | 
			
		||||
              },
 | 
			
		||||
              onSubmitted:
 | 
			
		||||
                  _isMessageValid ? (s) => _submitMessage(context, s) : null,
 | 
			
		||||
              onSubmitted: _isMessageValid
 | 
			
		||||
                  ? (s) => _submitTextMessage(context, s)
 | 
			
		||||
                  : null,
 | 
			
		||||
              decoration:
 | 
			
		||||
                  new InputDecoration.collapsed(hintText: tr("Send a message")),
 | 
			
		||||
            ),
 | 
			
		||||
@@ -184,7 +206,8 @@ class _ConversationScreenState extends State<ConversationScreen> {
 | 
			
		||||
                    : Theme.of(context).disabledColor,
 | 
			
		||||
              ),
 | 
			
		||||
              onPressed: !_isSendingMessage && _isMessageValid
 | 
			
		||||
                  ? () => _submitMessage(context, _textEditingController.text)
 | 
			
		||||
                  ? () =>
 | 
			
		||||
                      _submitTextMessage(context, _textEditingController.text)
 | 
			
		||||
                  : null,
 | 
			
		||||
            ),
 | 
			
		||||
          ),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user