feat: add flag for floating date divider
This commit is contained in:
@@ -161,6 +161,7 @@ class MessageListView extends StatefulWidget {
|
|||||||
this.pinPermissions = const [],
|
this.pinPermissions = const [],
|
||||||
this.textBuilder,
|
this.textBuilder,
|
||||||
this.usernameBuilder,
|
this.usernameBuilder,
|
||||||
|
this.showFloatingDateDivider = true,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Function used to build a custom message widget
|
/// Function used to build a custom message widget
|
||||||
@@ -227,6 +228,9 @@ class MessageListView extends StatefulWidget {
|
|||||||
/// Flag for showing tile on header
|
/// Flag for showing tile on header
|
||||||
final bool showConnectionStateTile;
|
final bool showConnectionStateTile;
|
||||||
|
|
||||||
|
/// Flag for showing the floating date divider
|
||||||
|
final bool showFloatingDateDivider;
|
||||||
|
|
||||||
/// Function called when messages are fetched
|
/// Function called when messages are fetched
|
||||||
final Widget Function(BuildContext, List<Message>)? messageListBuilder;
|
final Widget Function(BuildContext, List<Message>)? messageListBuilder;
|
||||||
|
|
||||||
@@ -567,49 +571,51 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (widget.showScrollToBottom) _buildScrollToBottom(),
|
if (widget.showScrollToBottom) _buildScrollToBottom(),
|
||||||
Positioned(
|
if (widget.showFloatingDateDivider) _buildFloatingDateDivider(),
|
||||||
top: 20,
|
|
||||||
child: BetterStreamBuilder<Iterable<ItemPosition>>(
|
|
||||||
initialData: _itemPositionListener.itemPositions.value,
|
|
||||||
stream: _itemPositionStream,
|
|
||||||
comparator: (a, b) {
|
|
||||||
if (a == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final aTop = _getTopElement(a)?.index;
|
|
||||||
final bTop = _getTopElement(b)?.index;
|
|
||||||
return aTop == bTop;
|
|
||||||
},
|
|
||||||
builder: (context, values) {
|
|
||||||
final items = _itemPositionListener.itemPositions.value;
|
|
||||||
if (items.isEmpty || messages.isEmpty) {
|
|
||||||
return const SizedBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
var index = _getTopElement(values)?.index;
|
|
||||||
|
|
||||||
if (index == null || index > messages.length) {
|
|
||||||
return const SizedBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index == messages.length) {
|
|
||||||
index = max(index - 1, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return widget.dateDividerBuilder != null
|
|
||||||
? widget.dateDividerBuilder!(
|
|
||||||
messages[index].createdAt.toLocal(),
|
|
||||||
)
|
|
||||||
: DateDivider(
|
|
||||||
dateTime: messages[index].createdAt.toLocal(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Positioned _buildFloatingDateDivider() => Positioned(
|
||||||
|
top: 20,
|
||||||
|
child: BetterStreamBuilder<Iterable<ItemPosition>>(
|
||||||
|
initialData: _itemPositionListener.itemPositions.value,
|
||||||
|
stream: _itemPositionStream,
|
||||||
|
comparator: (a, b) {
|
||||||
|
if (a == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final aTop = _getTopElement(a)?.index;
|
||||||
|
final bTop = _getTopElement(b)?.index;
|
||||||
|
return aTop == bTop;
|
||||||
|
},
|
||||||
|
builder: (context, values) {
|
||||||
|
final items = _itemPositionListener.itemPositions.value;
|
||||||
|
if (items.isEmpty || messages.isEmpty) {
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
var index = _getTopElement(values)?.index;
|
||||||
|
|
||||||
|
if (index == null || index > messages.length) {
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index == messages.length) {
|
||||||
|
index = max(index - 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return widget.dateDividerBuilder != null
|
||||||
|
? widget.dateDividerBuilder!(
|
||||||
|
messages[index].createdAt.toLocal(),
|
||||||
|
)
|
||||||
|
: DateDivider(
|
||||||
|
dateTime: messages[index].createdAt.toLocal(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
Future<void> _paginateData(
|
Future<void> _paginateData(
|
||||||
StreamChannelState? channel, QueryDirection direction) =>
|
StreamChannelState? channel, QueryDirection direction) =>
|
||||||
_messageListController.paginateData!(direction: direction);
|
_messageListController.paginateData!(direction: direction);
|
||||||
|
|||||||
Reference in New Issue
Block a user