fix(ui): fix date divider not showing (#1259)
* fix(ui): fix date divider not showing * chore(ui): update changelog * chore(ui): minor changes Signed-off-by: xsahil03x <[email protected]> * fix(ui): fix separator Signed-off-by: xsahil03x <[email protected]> Co-authored-by: Sahil Kumar <[email protected]>
This commit is contained in:
co-authored by
Sahil Kumar
parent
482d4ed611
commit
0cffd09415
@@ -3,6 +3,7 @@
|
|||||||
🐞 Fixed
|
🐞 Fixed
|
||||||
|
|
||||||
- [[#1247]](https://github.com/GetStream/stream-chat-flutter/issues/1247) Fix Jiffy initialization.
|
- [[#1247]](https://github.com/GetStream/stream-chat-flutter/issues/1247) Fix Jiffy initialization.
|
||||||
|
- [[#1232]](https://github.com/getstream/stream-chat-flutter/issues/1232) Fix DateDivider not showing up in the chat.
|
||||||
|
|
||||||
## 4.4.0
|
## 4.4.0
|
||||||
|
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ class StreamMessageListView extends StatefulWidget {
|
|||||||
this.paginationLimit = 20,
|
this.paginationLimit = 20,
|
||||||
this.paginationLoadingIndicatorBuilder,
|
this.paginationLoadingIndicatorBuilder,
|
||||||
this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.onDrag,
|
this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.onDrag,
|
||||||
this.spacingWidgetBuilder,
|
this.spacingWidgetBuilder = _defaultSpacingWidgetBuilder,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// [ScrollViewKeyboardDismissBehavior] the defines how this [PositionedList] will
|
/// [ScrollViewKeyboardDismissBehavior] the defines how this [PositionedList] will
|
||||||
@@ -353,7 +353,17 @@ class StreamMessageListView extends StatefulWidget {
|
|||||||
/// A List of [SpacingType] is provided to provide more data about the
|
/// A List of [SpacingType] is provided to provide more data about the
|
||||||
/// type of message (thread, difference in time between current and last
|
/// type of message (thread, difference in time between current and last
|
||||||
/// message, default spacing, etc)
|
/// message, default spacing, etc)
|
||||||
final SpacingWidgetBuilder? spacingWidgetBuilder;
|
final SpacingWidgetBuilder spacingWidgetBuilder;
|
||||||
|
|
||||||
|
static Widget _defaultSpacingWidgetBuilder(
|
||||||
|
BuildContext context,
|
||||||
|
List<SpacingType> spacingTypes,
|
||||||
|
) {
|
||||||
|
if (!spacingTypes.contains(SpacingType.defaultSpacing)) {
|
||||||
|
return const SizedBox(height: 8);
|
||||||
|
}
|
||||||
|
return const SizedBox(height: 2);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_StreamMessageListViewState createState() => _StreamMessageListViewState();
|
_StreamMessageListViewState createState() => _StreamMessageListViewState();
|
||||||
@@ -612,7 +622,6 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
late final Message message, nextMessage;
|
late final Message message, nextMessage;
|
||||||
late Widget separator;
|
|
||||||
if (widget.reverse) {
|
if (widget.reverse) {
|
||||||
message = messages[i - 1];
|
message = messages[i - 1];
|
||||||
nextMessage = messages[i - 2];
|
nextMessage = messages[i - 2];
|
||||||
@@ -621,84 +630,53 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
nextMessage = messages[i - 1];
|
nextMessage = messages[i - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget separator;
|
||||||
|
|
||||||
|
final isThread = message.replyCount! > 0;
|
||||||
|
|
||||||
if (!Jiffy(message.createdAt.toLocal()).isSame(
|
if (!Jiffy(message.createdAt.toLocal()).isSame(
|
||||||
nextMessage.createdAt.toLocal(),
|
nextMessage.createdAt.toLocal(),
|
||||||
Units.DAY,
|
Units.DAY,
|
||||||
)) {
|
)) {
|
||||||
separator = _buildDateDivider(nextMessage);
|
separator = _buildDateDivider(nextMessage);
|
||||||
|
} else {
|
||||||
|
final timeDiff =
|
||||||
|
Jiffy(nextMessage.createdAt.toLocal()).diff(
|
||||||
|
message.createdAt.toLocal(),
|
||||||
|
Units.MINUTE,
|
||||||
|
);
|
||||||
|
|
||||||
|
final isNextUserSame =
|
||||||
|
message.user!.id == nextMessage.user?.id;
|
||||||
|
final isDeleted = message.isDeleted;
|
||||||
|
final hasTimeDiff = timeDiff >= 1;
|
||||||
|
|
||||||
|
final spacingRules = [
|
||||||
|
if (hasTimeDiff) SpacingType.timeDiff,
|
||||||
|
if (!isNextUserSame) SpacingType.otherUser,
|
||||||
|
if (isThread) SpacingType.thread,
|
||||||
|
if (isDeleted) SpacingType.deleted,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (spacingRules.isEmpty) {
|
||||||
|
spacingRules.add(SpacingType.defaultSpacing);
|
||||||
|
}
|
||||||
|
|
||||||
|
separator = widget.spacingWidgetBuilder.call(
|
||||||
|
context,
|
||||||
|
spacingRules,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
final timeDiff =
|
|
||||||
Jiffy(nextMessage.createdAt.toLocal()).diff(
|
|
||||||
message.createdAt.toLocal(),
|
|
||||||
Units.MINUTE,
|
|
||||||
);
|
|
||||||
|
|
||||||
final spacingRules = <SpacingType>[];
|
|
||||||
|
|
||||||
final isNextUserSame =
|
|
||||||
message.user!.id == nextMessage.user?.id;
|
|
||||||
final isThread = message.replyCount! > 0;
|
|
||||||
final isDeleted = message.isDeleted;
|
|
||||||
final hasTimeDiff = timeDiff >= 1;
|
|
||||||
|
|
||||||
if (hasTimeDiff) {
|
|
||||||
spacingRules.add(SpacingType.timeDiff);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isNextUserSame) {
|
|
||||||
spacingRules.add(SpacingType.otherUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isThread) {
|
|
||||||
spacingRules.add(SpacingType.thread);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDeleted) {
|
|
||||||
spacingRules.add(SpacingType.deleted);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (spacingRules.isNotEmpty) {
|
|
||||||
separator = widget.spacingWidgetBuilder
|
|
||||||
?.call(context, spacingRules) ??
|
|
||||||
const SizedBox(height: 8);
|
|
||||||
}
|
|
||||||
separator = widget.spacingWidgetBuilder
|
|
||||||
?.call(context, [SpacingType.defaultSpacing]) ??
|
|
||||||
const SizedBox(height: 2);
|
|
||||||
|
|
||||||
if (!isThread && unreadCount > 0 && unreadCount == i - 1) {
|
if (!isThread && unreadCount > 0 && unreadCount == i - 1) {
|
||||||
final unreadMessagesSeparator = widget
|
final unreadMessagesSeparator =
|
||||||
.unreadMessagesSeparatorBuilder
|
_buildUnreadMessagesSeparator(unreadCount);
|
||||||
?.call(context, unreadCount);
|
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
separator,
|
separator,
|
||||||
unreadMessagesSeparator ??
|
unreadMessagesSeparator,
|
||||||
Padding(
|
|
||||||
padding:
|
|
||||||
const EdgeInsets.symmetric(vertical: 8),
|
|
||||||
child: DecoratedBox(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
gradient:
|
|
||||||
_streamTheme.colorTheme.bgGradient,
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: Text(
|
|
||||||
context.translations
|
|
||||||
.unreadMessagesSeparatorText(
|
|
||||||
unreadCount,
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style:
|
|
||||||
StreamChannelHeaderTheme.of(context)
|
|
||||||
.subtitleStyle,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -816,6 +794,30 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildUnreadMessagesSeparator(int unreadCount) {
|
||||||
|
final unreadMessagesSeparator =
|
||||||
|
widget.unreadMessagesSeparatorBuilder?.call(context, unreadCount) ??
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
gradient: _streamTheme.colorTheme.bgGradient,
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: Text(
|
||||||
|
context.translations.unreadMessagesSeparatorText(
|
||||||
|
unreadCount,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: StreamChannelHeaderTheme.of(context).subtitleStyle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return unreadMessagesSeparator;
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildDateDivider(Message message) {
|
Widget _buildDateDivider(Message message) {
|
||||||
final divider = widget.dateDividerBuilder != null
|
final divider = widget.dateDividerBuilder != null
|
||||||
? widget.dateDividerBuilder!(
|
? widget.dateDividerBuilder!(
|
||||||
|
|||||||
Reference in New Issue
Block a user