editMessage static method

dynamic editMessage(
  1. BaseMessage message, {
  2. required dynamic onSuccess(
    1. BaseMessage retMessage
    )?,
  3. required dynamic onError(
    1. CometChatException excep
    )?,
})

edit a message, you can use the editMessage() method

only allowed to edit TextMessage and CustomMessage

method could throw PlatformException with error codes specifying the cause

Implementation

static editMessage(BaseMessage message,
    {required Function(BaseMessage retMessage)? onSuccess,
    required Function(CometChatException excep)? onError}) async {
  try {
    late Map<String, dynamic> messageMap = message.toJson();
    final result = await channel
        .invokeMethod('editMessage', {'baseMessage': messageMap});
    late BaseMessage resultMessage;
    switch (message.type) {
      case CometChatMessageType.text:
        resultMessage = TextMessage.fromMap(result);
        break;
      case CometChatMessageType.custom:
        resultMessage = CustomMessage.fromMap(result);
        break;
      default:
        resultMessage = BaseMessage.fromMap(result);
        break;
    }
    if (onSuccess != null) onSuccess(resultMessage);
  } on PlatformException catch (p) {
    _errorCallbackHandler(null, p, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
}