sendImageMessage method

void sendImageMessage(
  1. String filePath,
  2. String? name,
  3. int width,
  4. int height, {
  5. NIMMessage? replyMsg,
  6. String? imageType,
  7. Uint8List? fileBytes,
})

Implementation

void sendImageMessage(
  String filePath,
  String? name,
  int width,
  int height, {
  NIMMessage? replyMsg,
  String? imageType,
  Uint8List? fileBytes,
}) {
  // Web 端需要构造 html.File 对象传入 imageObj 参数
  html.File? imageObj;
  if (kIsWeb && fileBytes != null) {
    final mimeType = imageType != null ? 'image/$imageType' : 'image/png';
    final blob = html.Blob([fileBytes], mimeType);
    imageObj = html.File([blob], name ?? 'image.$imageType');
  }
  MessageCreator.createImageMessage(
          filePath, name, kIsWeb ? 'nim_default_im' : null, width, height,
          imageObj: imageObj)
      .then(
    (value) {
      if (value.isSuccess) {
        if (imageType?.isNotEmpty == true) {
          value.data!.serverExtension = jsonEncode({
            ChatMessage.keyImageType: imageType,
          });
        }
        value.data?.text = name;
        sendMessage(value.data!, replyMsg: replyMsg);
      }
    },
  );
}