Rebuild only changed list rows and lay out big artifact sections lazily
Runs and chat session rows are memoized on their own data (MemoSubtree), so a run event or a chat's running change rebuilds one row instead of every built row. The artifact gallery's open sections are lazy slivers revealed by a sliver open/close animation, and thumbnails decode at display size. Benches in test/perf measure both.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/layout/memo_subtree.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('rebuilds only when the memo changes', (tester) async {
|
||||
var builds = 0;
|
||||
Widget host(Object memo) => Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: MemoSubtree(
|
||||
memo: memo,
|
||||
builder: (_) {
|
||||
builds++;
|
||||
return Text('$memo');
|
||||
},
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(host((MemoMap({'id': 1, 'a': 'x'}), true)));
|
||||
// An equal map (a new instance) and equal props keep the built child.
|
||||
await tester.pumpWidget(host((MemoMap({'id': 1, 'a': 'x'}), true)));
|
||||
expect(builds, 1);
|
||||
await tester.pumpWidget(host((MemoMap({'id': 1, 'a': 'y'}), true)));
|
||||
expect(builds, 2);
|
||||
await tester.pumpWidget(host((MemoMap({'id': 1, 'a': 'y'}), false)));
|
||||
expect(builds, 3);
|
||||
});
|
||||
|
||||
testWidgets('the built subtree still follows its inherited widgets', (
|
||||
tester,
|
||||
) async {
|
||||
Widget host(Color color) => MaterialApp(
|
||||
theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: color)),
|
||||
home: MemoSubtree(
|
||||
memo: 1,
|
||||
builder: (_) => Builder(
|
||||
builder: (context) => ColoredBox(
|
||||
key: const Key('box'),
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
Color shown() =>
|
||||
tester.widget<ColoredBox>(find.byKey(const Key('box'))).color;
|
||||
await tester.pumpWidget(host(Colors.red));
|
||||
final before = shown();
|
||||
await tester.pumpWidget(host(Colors.blue));
|
||||
await tester.pumpAndSettle();
|
||||
expect(shown(), isNot(before));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/layout/sliver_reveal.dart';
|
||||
|
||||
void main() {
|
||||
Widget host({
|
||||
required bool open,
|
||||
Duration duration = kThemeAnimationDuration,
|
||||
}) => MaterialApp(
|
||||
home: CustomScrollView(
|
||||
slivers: [
|
||||
SliverReveal(
|
||||
open: open,
|
||||
duration: duration,
|
||||
curve: Curves.easeInOut,
|
||||
sliver: SliverList.builder(
|
||||
itemCount: 1000,
|
||||
itemBuilder: (_, index) =>
|
||||
SizedBox(height: 50, child: Text('item $index')),
|
||||
),
|
||||
),
|
||||
const SliverToBoxAdapter(child: Text('after')),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
double afterTop(WidgetTester tester) =>
|
||||
tester.getTopLeft(find.text('after')).dy;
|
||||
|
||||
testWidgets('closed builds nothing; open builds only the visible items', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(host(open: false));
|
||||
expect(find.textContaining('item'), findsNothing);
|
||||
expect(afterTop(tester), 0);
|
||||
|
||||
await tester.pumpWidget(host(open: true));
|
||||
await tester.pump(kThemeAnimationDuration ~/ 2);
|
||||
// Part-way open: the items reveal from the top, clipped at the extent.
|
||||
expect(find.text('item 0'), findsOneWidget);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('item 0'), findsOneWidget);
|
||||
expect(find.text('item 999', skipOffstage: false), findsNothing);
|
||||
expect(tester.widgetList(find.textContaining('item')).length, lessThan(40));
|
||||
});
|
||||
|
||||
testWidgets('closing shrinks the extent, then drops the items', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: CustomScrollView(
|
||||
slivers: [
|
||||
SliverReveal(
|
||||
open: true,
|
||||
duration: kThemeAnimationDuration,
|
||||
curve: Curves.linear,
|
||||
sliver: SliverList.list(
|
||||
children: [
|
||||
for (var i = 0; i < 4; i++)
|
||||
SizedBox(height: 50, child: Text('item $i')),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SliverToBoxAdapter(child: Text('after')),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(afterTop(tester), 200);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: CustomScrollView(
|
||||
slivers: [
|
||||
SliverReveal(
|
||||
open: false,
|
||||
duration: kThemeAnimationDuration,
|
||||
curve: Curves.linear,
|
||||
sliver: SliverList.list(
|
||||
children: [
|
||||
for (var i = 0; i < 4; i++)
|
||||
SizedBox(height: 50, child: Text('item $i')),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SliverToBoxAdapter(child: Text('after')),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump(kThemeAnimationDuration ~/ 2);
|
||||
expect(afterTop(tester), closeTo(100, 1));
|
||||
await tester.pumpAndSettle();
|
||||
expect(afterTop(tester), 0);
|
||||
expect(find.textContaining('item'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('no motion opens and closes at once', (tester) async {
|
||||
await tester.pumpWidget(host(open: false, duration: Duration.zero));
|
||||
await tester.pumpWidget(host(open: true, duration: Duration.zero));
|
||||
await tester.pump();
|
||||
expect(find.text('item 0'), findsOneWidget);
|
||||
await tester.pumpWidget(host(open: false, duration: Duration.zero));
|
||||
await tester.pump();
|
||||
expect(find.textContaining('item'), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user