MessageWidget constructor

MessageWidget({
  1. Key? key,
  2. required Message message,
  3. required MessageThemeData messageTheme,
  4. bool reverse = false,
  5. bool translateUserAvatar = true,
  6. ShapeBorder? shape,
  7. ShapeBorder? attachmentShape,
  8. BorderSide? borderSide,
  9. BorderSide? attachmentBorderSide,
  10. BorderRadiusGeometry? borderRadiusGeometry,
  11. BorderRadiusGeometry? attachmentBorderRadiusGeometry,
  12. void onMentionTap(
    1. User
    )?,
  13. void onMessageTap(
    1. Message
    )?,
  14. bool showReactionPickerIndicator = false,
  15. DisplayWidget showUserAvatar = DisplayWidget.show,
  16. bool showSendingIndicator = true,
  17. bool showThreadReplyIndicator = false,
  18. bool showInChannelIndicator = false,
  19. void onReplyTap(
    1. Message
    )?,
  20. void onThreadTap(
    1. Message
    )?,
  21. bool showUsername = true,
  22. bool showTimestamp = true,
  23. bool showReactions = true,
  24. bool showDeleteMessage = true,
  25. bool showEditMessage = true,
  26. bool showReplyMessage = true,
  27. bool showThreadReplyMessage = true,
  28. bool showResendMessage = true,
  29. bool showCopyMessage = true,
  30. bool showFlagButton = true,
  31. bool showPinButton = true,
  32. bool showPinHighlight = true,
  33. void onUserAvatarTap(
    1. User
    )?,
  34. void onLinkTap(
    1. String
    )?,
  35. void onMessageActions(
    1. BuildContext,
    2. Message
    )?,
  36. ShowMessageCallback? onShowMessage,
  37. Widget userAvatarBuilder(
    1. BuildContext,
    2. User
    )?,
  38. Widget editMessageInputBuilder(
    1. BuildContext,
    2. Message
    )?,
  39. Widget textBuilder(
    1. BuildContext,
    2. Message
    )?,
  40. Widget bottomRowBuilder(
    1. BuildContext,
    2. Message
    )?,
  41. Widget deletedBottomRowBuilder(
    1. BuildContext,
    2. Message
    )?,
  42. ValueChanged<ReturnActionType>? onReturnAction,
  43. Map<String, AttachmentBuilder>? customAttachmentBuilders,
  44. EdgeInsetsGeometry? padding,
  45. EdgeInsets textPadding = const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
  46. EdgeInsetsGeometry attachmentPadding = EdgeInsets.zero,
  47. @Deprecated(''' allRead is now deprecated and it will be removed in future releases. The MessageWidget now listens for read events on its own. ''') bool allRead = false,
  48. @Deprecated(''' readList is now deprecated and it will be removed in future releases. The MessageWidget now listens for read events on its own. ''') List<Read>? readList,
  49. OnQuotedMessageTap? onQuotedMessageTap,
  50. List<MessageAction> customActions = const [],
  51. void onAttachmentTap(
    1. Message message,
    2. Attachment attachment
    )?,
  52. Widget usernameBuilder(
    1. BuildContext,
    2. Message
    )?,
})

Implementation

MessageWidget({
  Key? key,
  required this.message,
  required this.messageTheme,
  this.reverse = false,
  this.translateUserAvatar = true,
  this.shape,
  this.attachmentShape,
  this.borderSide,
  this.attachmentBorderSide,
  this.borderRadiusGeometry,
  this.attachmentBorderRadiusGeometry,
  this.onMentionTap,
  this.onMessageTap,
  this.showReactionPickerIndicator = false,
  this.showUserAvatar = DisplayWidget.show,
  this.showSendingIndicator = true,
  this.showThreadReplyIndicator = false,
  this.showInChannelIndicator = false,
  this.onReplyTap,
  this.onThreadTap,
  this.showUsername = true,
  this.showTimestamp = true,
  this.showReactions = true,
  this.showDeleteMessage = true,
  this.showEditMessage = true,
  this.showReplyMessage = true,
  this.showThreadReplyMessage = true,
  this.showResendMessage = true,
  this.showCopyMessage = true,
  this.showFlagButton = true,
  this.showPinButton = true,
  this.showPinHighlight = true,
  this.onUserAvatarTap,
  this.onLinkTap,
  this.onMessageActions,
  this.onShowMessage,
  this.userAvatarBuilder,
  this.editMessageInputBuilder,
  this.textBuilder,
  this.bottomRowBuilder,
  this.deletedBottomRowBuilder,
  this.onReturnAction,
  this.customAttachmentBuilders,
  this.padding,
  this.textPadding = const EdgeInsets.symmetric(
    horizontal: 16,
    vertical: 8,
  ),
  this.attachmentPadding = EdgeInsets.zero,
  @Deprecated('''
  allRead is now deprecated and it will be removed in future releases.
  The MessageWidget now listens for read events on its own.
  ''') this.allRead = false,
  @Deprecated('''
  readList is now deprecated and it will be removed in future releases.
  The MessageWidget now listens for read events on its own.
  ''') this.readList,
  this.onQuotedMessageTap,
  this.customActions = const [],
  this.onAttachmentTap,
  this.usernameBuilder,
})  : attachmentBuilders = {
        'image': (context, message, attachments) {
          final border = RoundedRectangleBorder(
            borderRadius: attachmentBorderRadiusGeometry ?? BorderRadius.zero,
          );

          final mediaQueryData = MediaQuery.of(context);
          if (attachments.length > 1) {
            return Padding(
              padding: attachmentPadding,
              child: wrapAttachmentWidget(
                context,
                Material(
                  color: messageTheme.messageBackgroundColor,
                  child: ImageGroup(
                    size: Size(
                      mediaQueryData.size.width * 0.8,
                      mediaQueryData.size.height * 0.3,
                    ),
                    images: attachments,
                    message: message,
                    messageTheme: messageTheme,
                    onShowMessage: onShowMessage,
                    onReturnAction: onReturnAction,
                    onAttachmentTap: onAttachmentTap,
                  ),
                ),
                border,
                reverse,
              ),
            );
          }

          return wrapAttachmentWidget(
            context,
            ImageAttachment(
              attachment: attachments[0],
              message: message,
              messageTheme: messageTheme,
              size: Size(
                mediaQueryData.size.width * 0.8,
                mediaQueryData.size.height * 0.3,
              ),
              onShowMessage: onShowMessage,
              onReturnAction: onReturnAction,
              onAttachmentTap: onAttachmentTap != null
                  ? () {
                      onAttachmentTap.call(message, attachments[0]);
                    }
                  : null,
            ),
            border,
            reverse,
          );
        },
        'video': (context, message, attachments) {
          final border = RoundedRectangleBorder(
            borderRadius: attachmentBorderRadiusGeometry ?? BorderRadius.zero,
          );

          return wrapAttachmentWidget(
            context,
            Column(
              children: attachments.map((attachment) {
                final mediaQueryData = MediaQuery.of(context);
                return VideoAttachment(
                  attachment: attachment,
                  messageTheme: messageTheme,
                  size: Size(
                    mediaQueryData.size.width * 0.8,
                    mediaQueryData.size.height * 0.3,
                  ),
                  message: message,
                  onShowMessage: onShowMessage,
                  onReturnAction: onReturnAction,
                  onAttachmentTap: onAttachmentTap != null
                      ? () {
                          onAttachmentTap(message, attachment);
                        }
                      : null,
                );
              }).toList(),
            ),
            border,
            reverse,
          );
        },
        'giphy': (context, message, attachments) {
          final border = RoundedRectangleBorder(
            borderRadius: attachmentBorderRadiusGeometry ?? BorderRadius.zero,
          );

          return wrapAttachmentWidget(
            context,
            Column(
              children: attachments.map((attachment) {
                final mediaQueryData = MediaQuery.of(context);
                return GiphyAttachment(
                  attachment: attachment,
                  message: message,
                  size: Size(
                    mediaQueryData.size.width * 0.8,
                    mediaQueryData.size.height * 0.3,
                  ),
                  onShowMessage: onShowMessage,
                  onReturnAction: onReturnAction,
                  onAttachmentTap: onAttachmentTap != null
                      ? () {
                          onAttachmentTap(message, attachment);
                        }
                      : null,
                );
              }).toList(),
            ),
            border,
            reverse,
          );
        },
        'file': (context, message, attachments) {
          final border = RoundedRectangleBorder(
            side: attachmentBorderSide ??
                BorderSide(
                  color: StreamChatTheme.of(context).colorTheme.borders,
                ),
            borderRadius: attachmentBorderRadiusGeometry ?? BorderRadius.zero,
          );

          return Column(
            children: attachments
                .map<Widget>((attachment) {
                  final mediaQueryData = MediaQuery.of(context);
                  return wrapAttachmentWidget(
                    context,
                    FileAttachment(
                      message: message,
                      attachment: attachment,
                      size: Size(
                        mediaQueryData.size.width * 0.8,
                        mediaQueryData.size.height * 0.3,
                      ),
                      onAttachmentTap: onAttachmentTap != null
                          ? () {
                              onAttachmentTap(message, attachment);
                            }
                          : null,
                    ),
                    border,
                    reverse,
                  );
                })
                .insertBetween(SizedBox(
                  height: attachmentPadding.vertical / 2,
                ))
                .toList(),
          );
        },
      }..addAll(customAttachmentBuilders ?? {}),
      super(key: key);