bubbleAvatarBuilder property

ChatWidgetBuilder? bubbleAvatarBuilder
final

A callback function creates a widget to display as an avatar within each chat bubble.

The bubbleAvatarBuilder allows you to specify a custom widget that will be shown as an avatar within each chat bubble. This is particularly useful for displaying user avatars or profile pictures in the chat interface.

The callback accepts three parameters: BuildContext, message index in the list, and ChatMessage and returns a Widget.

If a new instance is not assigned to this property, it will use the default avatar widget.


@override
Widget build(BuildContext context) {
  return SfChat(
    bubbleAvatarBuilder:
      (BuildContext context, int index, ChatMessage message) {
        return CircleAvatar(
          backgroundImage: NetworkImage(
            message.author.id == '123-001'
              ? 'https://example.com/outgoing-avatar.jpg'
              : 'https://example.com/incoming-avatar.jpg',
          ),
        );
      },
  );
}

See also:

  • The avatarPadding in ChatBubbleSettings for adjusting the padding of the bubbleAvatarBuilder.

Implementation

final ChatWidgetBuilder? bubbleAvatarBuilder;