Skip to content

Commit 271c55e

Browse files
committed
msglist [nfc]: Use names to clarify list-child index vs model-item index
1 parent e5983aa commit 271c55e

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

lib/widgets/message_list.dart

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
580580
}
581581

582582
Widget _buildListView(BuildContext context) {
583-
final length = model!.items.length;
583+
final numItems = model!.items.length;
584584
const centerSliverKey = ValueKey('center sliver');
585585
final zulipLocalizations = ZulipLocalizations.of(context);
586586

@@ -603,22 +603,24 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
603603
// have state that needs to be preserved have not been given keys
604604
// and will not trigger this callback.
605605
findChildIndexCallback: (Key key) {
606-
final valueKey = key as ValueKey<int>;
607-
final index = model!.findItemWithMessageId(valueKey.value);
608-
if (index == -1) return null;
609-
return length - 1 - (index - 3);
606+
final messageId = (key as ValueKey<int>).value;
607+
final itemIndex = model!.findItemWithMessageId(messageId);
608+
if (itemIndex == -1) return null;
609+
final childIndex = numItems - 1 - (itemIndex - 3);
610+
return childIndex;
610611
},
611-
childCount: length + 3,
612-
(context, i) {
612+
childCount: numItems + 3,
613+
(context, childIndex) {
613614
// To reinforce that the end of the feed has been reached:
614615
// https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/flutter.3A.20Mark-as-read/near/1680603
615-
if (i == 0) return const SizedBox(height: 36);
616+
if (childIndex == 0) return const SizedBox(height: 36);
616617

617-
if (i == 1) return MarkAsReadWidget(narrow: widget.narrow);
618+
if (childIndex == 1) return MarkAsReadWidget(narrow: widget.narrow);
618619

619-
if (i == 2) return TypingStatusWidget(narrow: widget.narrow);
620+
if (childIndex == 2) return TypingStatusWidget(narrow: widget.narrow);
620621

621-
final data = model!.items[length - 1 - (i - 3)];
622+
final itemIndex = numItems - 1 - (childIndex - 3);
623+
final data = model!.items[itemIndex];
622624
return _buildItem(zulipLocalizations, data);
623625
}));
624626

@@ -641,7 +643,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
641643
},
642644

643645
controller: scrollController,
644-
semanticChildCount: length, // TODO(#537): what's the right value for this?
646+
semanticChildCount: numItems, // TODO(#537): what's the right value for this?
645647
center: centerSliverKey,
646648
paintOrder: SliverPaintOrder.firstIsTop,
647649

0 commit comments

Comments
 (0)