Share one list row across runs, pipelines, chat, search and schedules

AppListRow (Material + Cupertino) with avatar, bold title and trailing
time, one muted line, one overflow menu style, inset dividers, selected
and emphasised states and a compact mode. Pipelines get a legible initial
avatar, schedule rows shrink to two lines with Edit/Pause/Delete in an
overflow menu, and the shell chat list scrolls behind the bar.
This commit is contained in:
2026-10-31 04:15:01 +00:00
parent 6ab8551348
commit 3c56db37fd
38 changed files with 1841 additions and 1520 deletions
+281
View File
@@ -0,0 +1,281 @@
import 'dart:ui' show Tristate;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/app_list_avatar.dart';
import 'package:pipelines_app/ui/layout/app_list_row.dart';
import 'package:pipelines_app/ui/layout/app_overflow_menu.dart';
const _longTitle = 'A row title long enough that it must ellipsise somewhere';
const _longLine = 'a muted line of facts that is far too long for one line';
Widget _host(bool cupertino, Widget child, {Brightness? brightness}) {
final body = ListView(children: [child]);
return cupertino
? CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
home: CupertinoPageScaffold(child: body),
)
: MaterialApp(
theme: ThemeData(brightness: brightness ?? Brightness.light),
home: Scaffold(body: body),
);
}
void _size(WidgetTester tester, double width, {double textScale = 1}) {
tester.view.physicalSize = Size(width, 800);
tester.view.devicePixelRatio = 1;
tester.platformDispatcher.textScaleFactorTestValue = textScale;
addTearDown(tester.view.reset);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
}
AppListRow _row({
String title = 'Fixture run',
String? time = '9d ago',
bool selected = false,
bool emphasized = false,
bool divider = true,
VoidCallback? onTap,
void Function(String)? onPicked,
}) => AppListRow(
key: const Key('row'),
selected: selected,
emphasized: emphasized,
divider: divider,
onTap: onTap ?? () {},
leading: const AppListAvatar(
key: Key('avatar'),
child: Icon(Icons.play_arrow),
),
title: Text(title),
time: time,
subtitle: const Text('pipeline · 2 stages'),
compactSubtitle: const Text('Running'),
subtitleLeading: const AppListStatusDot(
key: Key('dot'),
color: Color(0xFF00AA00),
semanticLabel: 'Running',
),
menu: AppOverflowMenu<String>(
key: const Key('menu'),
sheetTitle: title,
actions: const [
AppMenuAction(key: Key('menu-rename'), value: 'rename', label: 'Rename'),
AppMenuAction(
key: Key('menu-delete'),
value: 'delete',
label: 'Delete',
destructive: true,
),
],
onSelected: (_, value) => onPicked?.call(value),
),
);
TextStyle _paint(WidgetTester tester, String text) =>
tester.renderObject<RenderParagraph>(find.textContaining(text)).text.style!;
void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host: avatar, title with time, one line, menu, divider', (
tester,
) async {
_size(tester, 560);
var taps = 0;
String? picked;
await tester.pumpWidget(
_host(
cupertino,
_row(onTap: () => taps++, onPicked: (value) => picked = value),
),
);
final avatar = tester.getRect(find.byKey(const Key('avatar')));
final title = tester.getRect(find.text('Fixture run'));
final time = tester.getRect(find.text('9d ago'));
final line = tester.getRect(find.text('pipeline · 2 stages'));
final menu = tester.getRect(find.byKey(const Key('menu')));
expect(avatar.size, const Size.square(kAppListAvatarSize));
expect(avatar.right, lessThanOrEqualTo(title.left));
expect(time.left, greaterThan(title.right - 1));
expect(time.center.dy, closeTo(title.center.dy, 3));
expect(line.top, greaterThanOrEqualTo(title.bottom - 1));
expect(menu.left, greaterThanOrEqualTo(time.right));
expect(find.byKey(const Key('dot')), findsOneWidget);
// The title is bold, the line muted and smaller.
expect(_paint(tester, 'Fixture run').fontWeight, FontWeight.w600);
expect(
_paint(tester, 'pipeline').fontSize!,
lessThan(_paint(tester, 'Fixture run').fontSize!),
);
// The inset divider starts under the text column.
final divider = tester.getRect(find.byKey(appListRowDividerKey));
expect(divider.left, closeTo(title.left, 1));
await tester.tap(find.text('Fixture run'));
await tester.pumpAndSettle();
expect(taps, 1);
// One overflow icon per host; the menu items keep their keys.
expect(
find.descendant(
of: find.byKey(const Key('menu')),
matching: find.byIcon(
cupertino ? CupertinoIcons.ellipsis : Icons.more_vert,
),
),
findsOneWidget,
);
await tester.tap(find.byKey(const Key('menu')));
await tester.pumpAndSettle();
expect(taps, 1, reason: 'the menu is its own control');
if (cupertino) {
expect(find.byType(CupertinoActionSheet), findsOneWidget);
expect(find.text('Cancel'), findsOneWidget);
} else {
expect(find.byType(PopupMenuItem<String>), findsNWidgets(2));
}
await tester.tap(find.byKey(const Key('menu-delete')));
await tester.pumpAndSettle();
expect(picked, 'delete');
});
testWidgets('$host: selected and emphasised rows', (tester) async {
_size(tester, 560);
await tester.pumpWidget(
_host(cupertino, _row(selected: true, emphasized: true)),
);
final row = find.byKey(const Key('row'));
expect(
tester.getSemantics(row).flagsCollection.isSelected,
Tristate.isTrue,
);
final surface = find.descendant(
of: row,
matching: find.byKey(appListRowSurfaceKey),
);
final context = tester.element(row);
expect(
cupertino
? tester.widget<ColoredBox>(surface).color
: tester.widget<Material>(surface).color,
AppListRow.selectedColor(context, cupertino: cupertino),
);
final accent = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
expect(_paint(tester, 'Fixture run').fontWeight, FontWeight.w700);
expect(_paint(tester, '9d ago').color, accent);
await tester.pumpWidget(_host(cupertino, _row()));
expect(
cupertino
? tester.widget<ColoredBox>(surface).color
: tester.widget<Material>(surface).color,
const Color(0x00000000),
);
expect(_paint(tester, '9d ago').color, isNot(accent));
});
testWidgets('$host: a narrow pane drops the avatar, time and menu', (
tester,
) async {
_size(tester, 240);
await tester.pumpWidget(_host(cupertino, _row()));
expect(find.byKey(const Key('avatar')), findsNothing);
expect(find.text('9d ago'), findsNothing);
expect(find.byKey(const Key('menu')), findsNothing);
expect(find.text('Running'), findsOneWidget);
expect(find.text('pipeline · 2 stages'), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets('$host: keepMenuWhenCompact keeps the menu', (tester) async {
_size(tester, 240);
await tester.pumpWidget(
_host(
cupertino,
AppListRow(
keepMenuWhenCompact: true,
title: const Text('Chat'),
menu: AppOverflowMenu<int>(
key: const Key('menu'),
actions: const [AppMenuAction(value: 1, label: 'Star')],
onSelected: (_, _) {},
),
),
),
);
expect(find.byKey(const Key('menu')), findsOneWidget);
});
for (final brightness in Brightness.values) {
testWidgets('$host ${brightness.name}: 320px at 2x text ellipsises '
'without overflow', (tester) async {
_size(tester, 320, textScale: 2);
await tester.pumpWidget(
_host(
cupertino,
brightness: brightness,
AppListRow(
key: const Key('row'),
onTap: () {},
leading: const AppListAvatar(
key: Key('avatar'),
child: Text('P'),
),
title: const Text(_longTitle),
time: '12 days ago',
subtitle: const Text(_longLine),
menu: AppOverflowMenu<int>(
key: const Key('menu'),
actions: const [AppMenuAction(value: 1, label: 'Star')],
onSelected: (_, _) {},
),
),
),
);
expect(tester.takeException(), isNull);
final title = tester.renderObject<RenderParagraph>(
find.text(_longTitle),
);
expect(title.maxLines, 1);
expect(title.didExceedMaxLines, isTrue);
final line = tester.renderObject<RenderParagraph>(find.text(_longLine));
expect(line.maxLines, 1);
expect(line.didExceedMaxLines, isTrue);
final row = tester.getRect(find.byKey(const Key('row')));
expect(
tester.getRect(find.text('12 days ago')).right,
lessThanOrEqualTo(row.right),
);
// The avatar keeps its size; its glyph scales down inside it.
expect(
tester.getSize(find.byKey(const Key('avatar'))),
const Size.square(kAppListAvatarSize),
);
expect(find.byKey(const Key('menu')), findsOneWidget);
});
}
}
testWidgets('the initial avatar reads the first letter, upper case', (
tester,
) async {
await tester.pumpWidget(
MaterialApp(
home: Center(
child: AppListAvatar.initial(' beta flow', color: Colors.teal),
),
),
);
expect(find.text('B'), findsOneWidget);
expect(_paint(tester, 'B').fontSize, 18);
expect(_paint(tester, 'B').fontWeight, FontWeight.w700);
});
}