Skip to content

Commit

Permalink
Default bubbled message to the bubbleBuilder (#553)
Browse files Browse the repository at this point in the history
* Update message.dart

Changes to the bubbleBuilder.  It now creates the default message, and sends it to the bubbleBuilder(). This way people can just spit back message as they see fit or wrap the message with their own widgets.

* Update chat.dart

Changed the definition for the bubbleBuilder.  It now has a defaultBubbleMessage which is the original message.
  • Loading branch information
asoap authored Feb 4, 2024
1 parent 3e0656d commit a34e062
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
1 change: 1 addition & 0 deletions lib/src/widgets/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Chat extends StatefulWidget {
Widget child, {
required types.Message message,
required bool nextMessageInGroup,
required Widget defaultBubbleMessage,
})? bubbleBuilder;

/// See [Message.bubbleRtlAlignment].
Expand Down
45 changes: 23 additions & 22 deletions lib/src/widgets/message/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Message extends StatelessWidget {
Widget child, {
required types.Message message,
required bool nextMessageInGroup,
required Widget defaultBubbleMessage,
})? bubbleBuilder;

/// Determine the alignment of the bubble for RTL languages. Has no effect
Expand Down Expand Up @@ -205,28 +206,28 @@ class Message extends StatelessWidget {
BorderRadius borderRadius,
bool currentUserIsAuthor,
bool enlargeEmojis,
) =>
bubbleBuilder != null
? bubbleBuilder!(
_messageBuilder(),
message: message,
nextMessageInGroup: roundBorder,
)
: enlargeEmojis && hideBackgroundOnEmojiMessages
? _messageBuilder()
: Container(
decoration: BoxDecoration(
borderRadius: borderRadius,
color: !currentUserIsAuthor ||
message.type == types.MessageType.image
? InheritedChatTheme.of(context).theme.secondaryColor
: InheritedChatTheme.of(context).theme.primaryColor,
),
child: ClipRRect(
borderRadius: borderRadius,
child: _messageBuilder(),
),
);
) {
Widget defaultMessage = (enlargeEmojis && hideBackgroundOnEmojiMessages)
? _messageBuilder()
: Container(
decoration: BoxDecoration(
borderRadius: borderRadius,
color: !currentUserIsAuthor || message.type == types.MessageType.image ? InheritedChatTheme.of(context).theme.secondaryColor : InheritedChatTheme.of(context).theme.primaryColor,
),
child: ClipRRect(
borderRadius: borderRadius,
child: _messageBuilder(),
),
);
return bubbleBuilder != null
? bubbleBuilder!(
_messageBuilder(),
message: message,
nextMessageInGroup: roundBorder,
defaultBubbleMessage: defaultMessage,
)
: defaultMessage;
}

Widget _messageBuilder() {
switch (message.type) {
Expand Down

0 comments on commit a34e062

Please sign in to comment.