sendMessage method Null safety

Future<EMMessage> sendMessage(
  1. EMMessage message
)

Sends a message.

Note For attachment messages such as voice, image, or video messages, the SDK automatically uploads the attachment. You can set whether to upload the attachment to the chat sever using {@link EMOptions#serverTransfer(boolean)}.

To listen for the status of sending messages, call {@link EMMessage#setMessageStatusListener(EMMessageStatusListener)}.

Param message The message object to be sent: {@link EMMessage}.

Throws A description of the exception. See {@link EMError}.

Implementation

Future<EMMessage> sendMessage(EMMessage message) async {
  message.status = MessageStatus.PROGRESS;
  Map result = await EMMethodChannel.ChatManager.invokeMethod(
      ChatMethodKeys.sendMessage, message.toJson());
  try {
    EMError.hasErrorFromResult(result);
    EMMessage msg = EMMessage.fromJson(result[ChatMethodKeys.sendMessage]);
    message.from = msg.from;
    message.to = msg.to;
    message.status = msg.status;
    return message;
  } on EMError catch (e) {
    throw e;
  }
}