Skip to content

Commit

Permalink
Merge pull request #471 from GetStream/feat/threadSeparator
Browse files Browse the repository at this point in the history
feat: thread separator
  • Loading branch information
imtoori authored Jun 14, 2021
2 parents 1f68587 + 850145f commit e70a23a
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions packages/stream_chat_flutter/lib/src/message_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class MessageListView extends StatefulWidget {
this.textBuilder,
this.usernameBuilder,
this.showFloatingDateDivider = true,
this.threadSeparatorBuilder,
}) : super(key: key);

/// Function used to build a custom message widget
Expand Down Expand Up @@ -277,6 +278,9 @@ class MessageListView extends StatefulWidget {
/// A List of user types that have permission to pin messages
final List<String> pinPermissions;

/// Builder used to build the thread separator in case it's a thread view
final WidgetBuilder? threadSeparatorBuilder;

@override
_MessageListViewState createState() => _MessageListViewState();
}
Expand Down Expand Up @@ -450,22 +454,7 @@ class _MessageListViewState extends State<MessageListView> {
if (i == messages.length) return const Offstage();
if (i == 0) return const SizedBox(height: 30);
if (i == messages.length + 1) {
final replyCount = widget.parentMessage!.replyCount;
return Container(
decoration: BoxDecoration(
gradient: _streamTheme.colorTheme.bgGradient,
),
child: Padding(
padding: const EdgeInsets.all(8),
child: Text(
// ignore: lines_longer_than_80_chars
'$replyCount ${replyCount == 1 ? 'Reply' : 'Replies'}',
textAlign: TextAlign.center,
style: _streamTheme
.channelTheme.channelHeaderTheme.subtitle,
),
),
);
return _buildThreadSeparator();
}

final message = messages[i];
Expand Down Expand Up @@ -576,6 +565,28 @@ class _MessageListViewState extends State<MessageListView> {
);
}

Widget _buildThreadSeparator() {
if (widget.threadSeparatorBuilder != null) {
return widget.threadSeparatorBuilder!.call(context);
}

final replyCount = widget.parentMessage!.replyCount;
return DecoratedBox(
decoration: BoxDecoration(
gradient: _streamTheme.colorTheme.bgGradient,
),
child: Padding(
padding: const EdgeInsets.all(8),
child: Text(
// ignore: lines_longer_than_80_chars
'$replyCount ${replyCount == 1 ? 'Reply' : 'Replies'}',
textAlign: TextAlign.center,
style: _streamTheme.channelTheme.channelHeaderTheme.subtitle,
),
),
);
}

Positioned _buildFloatingDateDivider() => Positioned(
top: 20,
child: BetterStreamBuilder<Iterable<ItemPosition>>(
Expand Down

0 comments on commit e70a23a

Please sign in to comment.