sendMediaMessage static method
- MediaMessage mediaMessage, {
- required dynamic onSuccess(
- MediaMessage message
- required dynamic onError(
- CometChatException excep
send a media message like photos, videos & files.
filePath The file path object to be sent, need to prefix the path with 'file://' for IOS.
messageType type of the message that needs to be sent image,video,audio,file
receiver Group or User class from which UID and GUID will be fetched according to need.
receiverType ype of the receiver to whom the message is to be sent user,group.
On success, you will receive an object of the MediaMessage class containing all the information related to the sent media message.
Migration Note: Migrated from platform channels to native Dart implementation. Behavior and signature remain identical for backward compatibility.
Android Reference: MessagesRequest.sendMediaMessage(MediaMessage message)
The method could throw PlatformException with error codes specifying the cause
Implementation
static Future<MediaMessage?> sendMediaMessage(MediaMessage mediaMessage,
{required Function(MediaMessage message)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call native Dart message repository
final sentMessage = await sdk.messages.sendMediaMessage(mediaMessage);
// Call success callback
if (onSuccess != null) onSuccess(sentMessage);
return sentMessage;
} on SdkException catch (sdkEx) {
// Convert SdkException to CometChatException
final cometChatEx = CometChatException(
sdkEx.code,
sdkEx.details ?? sdkEx.message,
sdkEx.message,
);
_errorCallbackHandler(cometChatEx, null, null, onError);
} catch (e) {
_errorCallbackHandler(null, null, e, onError);
}
return null;
}