editMessage static method
- BaseMessage message,
- {required dynamic onSuccess(
- BaseMessage retMessage
- required dynamic onError(
- 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 (platformException) {
if(onError != null) onError(CometChatException(platformException.code, platformException.details, platformException.message));
} catch (e) {
debugPrint("Error: $e");
if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
}
}