Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom unread header builder #632

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions lib/src/widgets/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Chat extends StatefulWidget {
this.slidableMessageBuilder,
this.isLeftStatus = false,
this.messageWidthRatio = 0.72,
this.unreadHeaderDataBuilder,
});

/// See [Message.audioMessageBuilder].
Expand Down Expand Up @@ -143,6 +144,9 @@ class Chat extends StatefulWidget {
/// Custom date header builder gives ability to customize date header widget.
final Widget Function(DateHeader)? dateHeaderBuilder;

// Custom unread header data builder gives ability to customize header for unread messages.
final Widget Function(UnreadHeaderData)? unreadHeaderDataBuilder;

/// Time (in ms) between two messages when we will render a date header.
/// Default value is 15 minutes, 900000 ms. When time between two messages
/// is higher than this threshold, date header will be rendered. Also,
Expand Down Expand Up @@ -457,14 +461,15 @@ class ChatState extends State<Chat> {
height: object.height,
);
} else if (object is UnreadHeaderData) {
return AutoScrollTag(
controller: _scrollController,
index: index ?? -1,
key: const Key('unread_header'),
child: UnreadHeader(
marginTop: object.marginTop,
),
);
return widget.unreadHeaderDataBuilder?.call(object) ??
AutoScrollTag(
controller: _scrollController,
index: index ?? -1,
key: const Key('unread_header'),
child: UnreadHeader(
marginTop: object.marginTop,
),
);
} else {
final map = object as Map<String, Object>;
final message = map['message']! as types.Message;
Expand Down
Loading