getMessageBubble static method

Widget getMessageBubble({
  1. required BaseMessage message,
  2. CometChatMessageTemplate? template,
  3. required BubbleAlignment bubbleAlignment,
  4. required CometChatColorPalette colorPalette,
  5. required CometChatTypography typography,
  6. required CometChatSpacing spacing,
  7. required BuildContext context,
  8. List<CometChatTextFormatter>? textFormatters,
  9. CometChatOutgoingMessageBubbleStyle? outgoingMessageBubbleStyle,
  10. CometChatIncomingMessageBubbleStyle? incomingMessageBubbleStyle,
  11. Key? key,
  12. bool? receiptsVisibility,
})

Implementation

static Widget getMessageBubble({
  required BaseMessage message,
  CometChatMessageTemplate? template,
  required BubbleAlignment bubbleAlignment,
  required CometChatColorPalette colorPalette,
  required CometChatTypography typography,
  required CometChatSpacing spacing,
  required BuildContext context,
  List<CometChatTextFormatter>? textFormatters,
  CometChatOutgoingMessageBubbleStyle? outgoingMessageBubbleStyle,
  CometChatIncomingMessageBubbleStyle? incomingMessageBubbleStyle,
  Key? key,
  bool? receiptsVisibility,
}) {
  if (message.deletedAt == null && template?.bubbleView != null) {
    return template?.bubbleView!(message, context, BubbleAlignment.left) ??
        const SizedBox();
  }
  Widget? contentView;
  Widget? statusInfoView;
  Widget? leadingView;
  Widget? headerView;

  final outgoingMessageBubbleStyle0 =
      CometChatThemeHelper.getTheme<CometChatOutgoingMessageBubbleStyle>(
              context: context,
              defaultTheme: CometChatOutgoingMessageBubbleStyle.of)
          .merge(outgoingMessageBubbleStyle);
  final incomingMessageBubbleStyle0 =
      CometChatThemeHelper.getTheme<CometChatIncomingMessageBubbleStyle>(
              context: context,
              defaultTheme: CometChatIncomingMessageBubbleStyle.of)
          .merge(incomingMessageBubbleStyle);

  final bubbleStyleData = BubbleUIBuilder.getBubbleStyle(
      message,
      outgoingMessageBubbleStyle0,
      incomingMessageBubbleStyle0,
      colorPalette,
      typography,
      spacing);
  final additionalConfigurations =
      BubbleUIBuilder.getAdditionalConfigurations(
          context,
          message,
          textFormatters,
          incomingMessageBubbleStyle0,
          outgoingMessageBubbleStyle0,
          null);

  contentView = _getSuitableContentView(message, colorPalette, context,
      template, bubbleAlignment, additionalConfigurations);

  statusInfoView = _getStatusInfoView(
      bubbleAlignment,
      message,
      context,
      colorPalette,
      typography,
      spacing,
      template,
      bubbleStyleData?.messageBubbleDateStyle,
      bubbleStyleData?.messageReceiptStyle,
      receiptsVisibility,
  );

  leadingView = _getAvatar(
    bubbleAlignment,
    message,
    context,
    colorPalette,
    typography,
    spacing,
    template,
    bubbleStyleData?.messageBubbleAvatarStyle,
  );

  headerView = _getHeaderView(
    bubbleAlignment,
    message,
    context,
    colorPalette,
    typography,
    spacing,
    template,
    bubbleStyleData,
  );

  Color backgroundColor = bubbleStyleData?.backgroundColor ??
      _getBubbleBackgroundColor(
        message,
        template,
        colorPalette,
        bubbleAlignment,
      );

  return Column(
    key: key,
    children: [
      Row(
        mainAxisAlignment: bubbleAlignment == BubbleAlignment.left
            ? MainAxisAlignment.start
            : bubbleAlignment == BubbleAlignment.center
                ? MainAxisAlignment.center
                : MainAxisAlignment.end,
        children: [
          CometChatMessageBubble(
            style: CometChatMessageBubbleStyle(
              backgroundColor: backgroundColor,
              border: bubbleStyleData?.border,
              borderRadius: bubbleStyleData?.borderRadius,
              backgroundImage: bubbleStyleData?.messageBubbleBackgroundImage,
            ),
            headerView: headerView,
            alignment: bubbleAlignment,
            contentView: contentView,
            footerView: const SizedBox(),
            leadingView: leadingView,
            statusInfoView: statusInfoView,
          ),
        ],
      ),
    ],
  );
}