BubbleGroupBuilder class

A widget that builds a vertically stacked list of chat bubbles with automatic message grouping.

Consecutive messages from the same sender (within groupingThreshold) are grouped together. The last message in each group receives a tail (GroupInfo.showTail = true); earlier messages in the same group do not.

Use itemBuilder to construct the appropriate bubble widget. The GroupInfo parameter tells you whether to show the tail, an avatar, etc.

Example

final messages = ['Hello', 'How are you?', 'Good thanks!'];
final senders  = ['alice', 'alice', 'bob'];

BubbleGroupBuilder(
  itemCount: messages.length,
  senderIdOf: (i) => senders[i],
  itemBuilder: (context, i, info) => BubbleNormal(
    text: messages[i],
    isSender: senders[i] == 'bob',
    tail: info.showTail,
    color: senders[i] == 'bob'
        ? const Color(0xFFE8E8EE)
        : const Color(0xFF1B97F3),
  ),
)
Inheritance

Constructors

BubbleGroupBuilder({Key? key, required int itemCount, required String senderIdOf(int index), required Widget itemBuilder(BuildContext context, int index, GroupInfo info), DateTime? timestampOf(int index)?, Duration groupingThreshold = const Duration(minutes: 1), double itemSpacing = 2.0, double groupSpacing = 8.0})
Creates a BubbleGroupBuilder widget
const

Properties

groupingThreshold Duration
Maximum time gap between two consecutive messages from the same sender before they are split into separate groups. Defaults to 1 minute.
final
groupSpacing double
Vertical spacing between separate groups
final
hashCode int
The hash code for this object.
no setterinherited
itemBuilder Widget Function(BuildContext context, int index, GroupInfo info)
Builds the bubble widget for index.
final
itemCount int
Total number of messages
final
itemSpacing double
Vertical spacing between bubbles within the same group
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
senderIdOf String Function(int index)
Returns the sender identifier for the message at index
final
timestampOf DateTime? Function(int index)?
Optional: returns the send timestamp for the message at index. Used to break groups when a time gap exceeds groupingThreshold.
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited