loadMessage method Null safety

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

Loads a message from the local database by message ID.

Param messageId The message ID.

Return The message object specified by the message ID. Returns null if the message does not exist.

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

Implementation

Future<EMMessage?> loadMessage(String messageId) async {
  Map req = {"msg_id": messageId};
  Map<String, dynamic> result =
      await EMMethodChannel.ChatManager.invokeMethod(
          ChatMethodKeys.getMessage, req);
  try {
    EMError.hasErrorFromResult(result);
    if (result.containsKey(ChatMethodKeys.getMessage)) {
      return EMMessage.fromJson(result[ChatMethodKeys.getMessage]);
    } else {
      return null;
    }
  } on EMError catch (e) {
    throw e;
  }
}