File tree 3 files changed +16
-3
lines changed
3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -137,8 +137,17 @@ mixin _MessageSequence {
137
137
/// This information is completely derived from [messages] and
138
138
/// the flags [haveOldest] , [fetchingOlder] and [fetchOlderCoolingDown] .
139
139
/// It exists as an optimization, to memoize that computation.
140
+ ///
141
+ /// See also [middleItem] , an index which divides this list
142
+ /// into a top slice and a bottom slice.
140
143
final QueueList <MessageListItem > items = QueueList ();
141
144
145
+ /// An index into [items] dividing it into a top slice and a bottom slice.
146
+ ///
147
+ /// The indices 0 to before [middleItem] are the top slice of [items] ,
148
+ /// and the indices from [middleItem] to the end are the bottom slice.
149
+ int get middleItem => items.isEmpty ? 0 : items.length - 1 ;
150
+
142
151
int _findMessageWithId (int messageId) {
143
152
return binarySearchByKey (messages, messageId,
144
153
(message, messageId) => message.id.compareTo (messageId));
Original file line number Diff line number Diff line change @@ -573,10 +573,9 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
573
573
// The list has two slivers: a top sliver growing upward,
574
574
// and a bottom sliver growing downward.
575
575
// Each sliver has some of the items from `model.items`.
576
- const maxBottomItems = 1 ;
577
576
final totalItems = model.items.length;
578
- final bottomItems = totalItems <= maxBottomItems ? totalItems : maxBottomItems ;
579
- final topItems = totalItems - bottomItems ;
577
+ final topItems = model.middleItem ;
578
+ final bottomItems = totalItems - topItems ;
580
579
581
580
// The top sliver has its child 0 as the item just before the
582
581
// sliver boundary, child 1 as the item before that, and so on.
Original file line number Diff line number Diff line change @@ -1997,6 +1997,10 @@ void checkInvariants(MessageListView model) {
1997
1997
});
1998
1998
}
1999
1999
check (model.items).length.equals (i);
2000
+
2001
+ check (model).middleItem
2002
+ ..isGreaterOrEqual (0 )
2003
+ ..isLessOrEqual (model.items.length);
2000
2004
}
2001
2005
2002
2006
extension MessageListRecipientHeaderItemChecks on Subject <MessageListRecipientHeaderItem > {
@@ -2024,6 +2028,7 @@ extension MessageListViewChecks on Subject<MessageListView> {
2024
2028
Subject <List <Message >> get messages => has ((x) => x.messages, 'messages' );
2025
2029
Subject <List <ZulipMessageContent >> get contents => has ((x) => x.contents, 'contents' );
2026
2030
Subject <List <MessageListItem >> get items => has ((x) => x.items, 'items' );
2031
+ Subject <int > get middleItem => has ((x) => x.middleItem, 'middleItem' );
2027
2032
Subject <bool > get fetched => has ((x) => x.fetched, 'fetched' );
2028
2033
Subject <bool > get haveOldest => has ((x) => x.haveOldest, 'haveOldest' );
2029
2034
Subject <bool > get fetchingOlder => has ((x) => x.fetchingOlder, 'fetchingOlder' );
You can’t perform that action at this time.
0 commit comments