add thread separator builder

This commit is contained in:
Salvatore Giordano
2021-06-11 16:37:30 +02:00
parent 1f685871cc
commit 850145f791
@@ -162,6 +162,7 @@ class MessageListView extends StatefulWidget {
this.textBuilder, this.textBuilder,
this.usernameBuilder, this.usernameBuilder,
this.showFloatingDateDivider = true, this.showFloatingDateDivider = true,
this.threadSeparatorBuilder,
}) : super(key: key); }) : super(key: key);
/// Function used to build a custom message widget /// Function used to build a custom message widget
@@ -277,6 +278,9 @@ class MessageListView extends StatefulWidget {
/// A List of user types that have permission to pin messages /// A List of user types that have permission to pin messages
final List<String> pinPermissions; final List<String> pinPermissions;
/// Builder used to build the thread separator in case it's a thread view
final WidgetBuilder? threadSeparatorBuilder;
@override @override
_MessageListViewState createState() => _MessageListViewState(); _MessageListViewState createState() => _MessageListViewState();
} }
@@ -450,22 +454,7 @@ class _MessageListViewState extends State<MessageListView> {
if (i == messages.length) return const Offstage(); if (i == messages.length) return const Offstage();
if (i == 0) return const SizedBox(height: 30); if (i == 0) return const SizedBox(height: 30);
if (i == messages.length + 1) { if (i == messages.length + 1) {
final replyCount = widget.parentMessage!.replyCount; return _buildThreadSeparator();
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,
),
),
);
} }
final message = messages[i]; final message = messages[i];
@@ -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( Positioned _buildFloatingDateDivider() => Positioned(
top: 20, top: 20,
child: BetterStreamBuilder<Iterable<ItemPosition>>( child: BetterStreamBuilder<Iterable<ItemPosition>>(