Merge pull request #458 from GetStream/hotfix/reduce

fix: use of .reduce
This commit is contained in:
Salvatore Giordano
2021-05-27 16:12:11 +02:00
committed by GitHub
@@ -570,9 +570,9 @@ class _MessageListViewState extends State<MessageListView> {
return const SizedBox(); return const SizedBox();
} }
var index = _getTopElement(values).index; var index = _getTopElement(values)?.index;
if (index > messages.length) { if (index == null || index > messages.length) {
return const SizedBox(); return const SizedBox();
} }
@@ -598,10 +598,17 @@ class _MessageListViewState extends State<MessageListView> {
StreamChannelState? channel, QueryDirection direction) => StreamChannelState? channel, QueryDirection direction) =>
_messageListController.paginateData!(direction: direction); _messageListController.paginateData!(direction: direction);
ItemPosition _getTopElement(Iterable<ItemPosition> values) => values ItemPosition? _getTopElement(Iterable<ItemPosition> values) {
.where((ItemPosition position) => position.itemLeadingEdge < 0.9) final inView =
.reduce((ItemPosition max, ItemPosition position) => values.where((ItemPosition position) => position.itemLeadingEdge < 0.9);
position.itemLeadingEdge > max.itemLeadingEdge ? position : max);
if (inView.isEmpty) {
return null;
}
return inView.reduce((ItemPosition max, ItemPosition position) =>
position.itemLeadingEdge > max.itemLeadingEdge ? position : max);
}
Widget _buildScrollToBottom() => StreamBuilder<Tuple2<bool, int>>( Widget _buildScrollToBottom() => StreamBuilder<Tuple2<bool, int>>(
stream: Rx.combineLatest2( stream: Rx.combineLatest2(