loadMessage method Null safety

Future<EMMessage?> loadMessage(
  1. String messageId
)

Gets the message with a specific message ID.

If the message is already loaded into the memory cache, the message will be directly returned; otherwise, the message will be loaded from the local database and loaded in the memory.

Param messageId The message ID.

Return The message instance.

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

Implementation

Future<EMMessage?> loadMessage(String messageId) async {
  Map req = this._toJson();
  req['msg_id'] = messageId;
  Map result = await _emConversationChannel.invokeMethod(
      ChatMethodKeys.loadMsgWithId, req);
  try {
    EMError.hasErrorFromResult(result);
    if (result[ChatMethodKeys.loadMsgWithId] != null) {
      return EMMessage.fromJson(result[ChatMethodKeys.loadMsgWithId]);
    } else {
      return null;
    }
  } on EMError catch (e) {
    throw e;
  }
}