Perf round 4: lazy chat sessions list

Chat sections are slivers: a lazy, keyed SliverList under the same heading,
with SliverAnimatedExtent reproducing the clipped AnimatedSize for open,
close and arriving rows. The first Chat tab visit no longer builds every row
(150 chats: worst build frame 116 ms to 19 ms).
This commit is contained in:
2026-11-02 14:28:33 +00:00
parent 2f6d967f3b
commit 8fd55cb7eb
9 changed files with 597 additions and 188 deletions
@@ -3,6 +3,26 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/collapsible_list_section.dart';
Widget _app(bool cupertino, Widget body) => cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body));
Widget _list(ValueNotifier<int> rows) => ValueListenableBuilder<int>(
valueListenable: rows,
builder: (context, count, _) => CustomScrollView(
slivers: [
SliverCollapsibleListSection(
title: 'Group',
count: count,
itemCount: count,
itemKey: (i) => ValueKey(i),
itemBuilder: (_, i) => SizedBox(height: 40, child: Text('Row $i')),
),
const SliverToBoxAdapter(child: Text('After')),
],
),
);
void main() {
for (final cupertino in [false, true]) {
testWidgets(
@@ -15,32 +35,64 @@ void main() {
);
final rows = ValueNotifier<int>(1);
addTearDown(rows.dispose);
final body = ValueListenableBuilder<int>(
valueListenable: rows,
builder: (context, count, _) => SingleChildScrollView(
child: CollapsibleListSection(
title: 'Group',
count: count,
children: [for (var i = 0; i < count; i++) Text('Row $i')],
),
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body)),
);
await tester.pumpWidget(_app(cupertino, _list(rows)));
await tester.pumpAndSettle();
rows.value = 3;
await tester.pumpAndSettle();
await tester.pump();
expect(find.text('Row 2'), findsOneWidget);
expect(find.byType(AnimatedSize), findsNothing);
expect(tester.hasRunningAnimations, isFalse);
expect(tester.takeException(), isNull);
await tester.tap(find.text('Group'));
await tester.pumpAndSettle();
await tester.pump();
expect(find.text('Row 0'), findsNothing);
expect(tester.takeException(), isNull);
},
);
}
testWidgets('arriving rows, opening and closing animate the height', (
tester,
) async {
final rows = ValueNotifier<int>(2);
addTearDown(rows.dispose);
await tester.pumpWidget(_app(false, _list(rows)));
double after() => tester.getTopLeft(find.text('After')).dy;
final top = after() - 80;
// Rows arriving: what follows moves down over the animation.
rows.value = 4;
await tester.pump();
await tester.pump(const Duration(milliseconds: 60));
expect(after(), inExclusiveRange(top + 80, top + 160));
await tester.pumpAndSettle();
expect(after(), top + 160);
// Closing: the rows go at once and the space shrinks away.
await tester.tap(find.text('Group'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 60));
expect(find.text('Row 0'), findsNothing);
expect(after(), inExclusiveRange(top, top + 160));
await tester.pumpAndSettle();
expect(after(), top);
// Opening: the rows are drawn at once and revealed from the top.
await tester.tap(find.text('Group'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 60));
expect(find.text('Row 0'), findsOneWidget);
expect(after(), inExclusiveRange(top, top + 160));
await tester.pumpAndSettle();
expect(after(), top + 160);
});
testWidgets('only the visible rows of a long section are built', (
tester,
) async {
final rows = ValueNotifier<int>(500);
addTearDown(rows.dispose);
await tester.pumpWidget(_app(false, _list(rows)));
expect(find.text('Row 0'), findsOneWidget);
expect(find.text('Row 100'), findsNothing);
});
}