Remove Cupertino branches from layout widgets

Keep the public cupertino parameters for existing callers while making the layout widgets and focused tests Material-only. Remove unreachable Cupertino imports, helpers, widgets, and test variants without changing the Material path.
This commit is contained in:
2026-11-11 16:35:38 +00:00
parent edc503b228
commit a5912d9a1e
11 changed files with 262 additions and 547 deletions
+8 -21
View File
@@ -1,8 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
/// The leading circle every list row uses, as large as a native contact
/// avatar ([CircleAvatar]'s default).
const double kAppListAvatarSize = 40;
@@ -48,29 +45,19 @@ class AppListAvatar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final mark =
foreground ??
(cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant);
final mark = foreground ?? Theme.of(context).colorScheme.onSurfaceVariant;
final fill =
background ??
(foreground == null
? (cupertino
? CupertinoColors.systemGrey5.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainerHighest)
? Theme.of(context).colorScheme.surfaceContainerHighest
: mark.withValues(alpha: 0.14));
final initialStyle =
(cupertino
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.titleMedium ?? const TextStyle())
.copyWith(
color: mark,
fontSize: 18,
fontWeight: FontWeight.w700,
height: 1,
);
(Theme.of(context).textTheme.titleMedium ?? const TextStyle()).copyWith(
color: mark,
fontSize: 18,
fontWeight: FontWeight.w700,
height: 1,
);
final circle = SizedBox.square(
dimension: kAppListAvatarSize,
child: DecoratedBox(
+25 -121
View File
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
import 'app_list_avatar.dart';
/// Below this row width (a list pane squeezed beside its detail) a row is
@@ -31,12 +29,8 @@ const appListRowSurfaceKey = ValueKey<String>('app-list-row-surface');
const appListRowDividerKey = ValueKey<String>('app-list-row-divider');
const appListRowAccentKey = ValueKey<String>('app-list-row-accent');
bool _darkSurface(BuildContext context, bool cupertino) => cupertino
? CupertinoTheme.brightnessOf(context) == Brightness.dark
: Theme.of(context).brightness == Brightness.dark;
/// The app's one list row (runs, pipelines, chats, search results,
/// schedules), on both hosts.
/// schedules).
///
/// Layout: [leading] (an [AppListAvatar]), then a bold one-line [title] with
/// the [time] at its trailing edge, then one muted [subtitle] line (with an
@@ -48,10 +42,8 @@ bool _darkSurface(BuildContext context, bool cupertino) => cupertino
/// under the text column separates rows. Nothing has a fixed height: the row
/// grows with text scaling and every line ellipsises.
///
/// [selected] paints the open row (Material `secondaryContainer`, Cupertino
/// `tertiarySystemFill`); [emphasized] marks unread/attention (a heavier
/// title and an accent time). Material rows ripple; Cupertino rows highlight
/// while pressed, like a native table cell.
/// [selected] paints the open row (Material `secondaryContainer`); [emphasized]
/// marks unread/attention (a heavier title and an accent time). Rows ripple.
class AppListRow extends StatelessWidget {
const AppListRow({
super.key,
@@ -115,29 +107,28 @@ class AppListRow extends StatelessWidget {
final bool divider;
final double compactWidth;
/// Overrides the host detection (some features pick a style per platform).
/// Ignored: rows are always Material. Kept so existing callers compile.
final bool? cupertino;
/// The faint tint an unselected row with [accent] wears over the list.
/// The [cupertino] argument is ignored; the tint is always Material.
static Color? tintFor(
BuildContext context,
Color? accent, {
required bool cupertino,
}) =>
accent?.withValues(alpha: _darkSurface(context, cupertino) ? 0.12 : 0.07);
}) => accent?.withValues(
alpha: Theme.of(context).brightness == Brightness.dark ? 0.12 : 0.07,
);
/// The open row's fill on each host.
/// The open row's fill. The [cupertino] argument is ignored; the fill is
/// always Material `secondaryContainer`.
static Color selectedColor(BuildContext context, {required bool cupertino}) =>
cupertino
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
: Theme.of(context).colorScheme.secondaryContainer;
Theme.of(context).colorScheme.secondaryContainer;
@override
Widget build(BuildContext context) {
final cupertino = this.cupertino ?? usesCupertinoHost(context);
final styles = _RowStyles.of(
context,
cupertino: cupertino,
selected: selected,
emphasized: emphasized,
);
@@ -181,29 +172,19 @@ class AppListRow extends StatelessWidget {
],
),
);
final tint = tintFor(context, accent, cupertino: cupertino);
final surface = cupertino
? _CupertinoRowSurface(
tapKey: tapKey,
onTap: onTap,
onLongPress: onLongPress,
selected: selected,
tint: tint,
selectedFill: selectedFill,
child: content,
)
: Material(
key: appListRowSurfaceKey,
color: selected
? selectedFill ?? selectedColor(context, cupertino: false)
: tint ?? Colors.transparent,
child: InkWell(
key: tapKey,
onTap: onTap,
onLongPress: onLongPress,
child: content,
),
);
final tint = tintFor(context, accent, cupertino: false);
final surface = Material(
key: appListRowSurfaceKey,
color: selected
? selectedFill ?? selectedColor(context, cupertino: false)
: tint ?? Colors.transparent,
child: InkWell(
key: tapKey,
onTap: onTap,
onLongPress: onLongPress,
child: content,
),
);
// The colour bar runs the row's whole height, divider included, and
// the tint fills the divider's inset too, so coloured rows read as
// one band each.
@@ -229,9 +210,7 @@ class AppListRow extends StatelessWidget {
padding: EdgeInsetsDirectional.only(start: textStart),
child: SizedBox(
key: appListRowDividerKey,
height: cupertino
? 1 / MediaQuery.devicePixelRatioOf(context)
: 1,
height: 1,
child: ColoredBox(color: styles.divider),
),
);
@@ -353,26 +332,10 @@ class _RowStyles {
factory _RowStyles.of(
BuildContext context, {
required bool cupertino,
required bool selected,
required bool emphasized,
}) {
final weight = emphasized ? FontWeight.w700 : FontWeight.w600;
if (cupertino) {
final theme = CupertinoTheme.of(context);
final base = theme.textTheme.textStyle;
final muted = CupertinoColors.secondaryLabel.resolveFrom(context);
final small = base.copyWith(fontSize: 15, color: muted);
return _RowStyles(
base.copyWith(fontWeight: weight, letterSpacing: 0),
small,
small.copyWith(
color: emphasized ? theme.primaryColor : muted,
fontWeight: emphasized ? FontWeight.w600 : null,
),
CupertinoColors.separator.resolveFrom(context),
);
}
final theme = Theme.of(context);
final scheme = theme.colorScheme;
final text = theme.textTheme;
@@ -397,62 +360,3 @@ class _RowStyles {
final TextStyle time;
final Color divider;
}
/// A Cupertino table cell: highlights while pressed, tinted while selected.
class _CupertinoRowSurface extends StatefulWidget {
const _CupertinoRowSurface({
required this.tapKey,
required this.onTap,
required this.selected,
this.onLongPress,
this.tint,
this.selectedFill,
required this.child,
});
/// The unselected row's tint, transparent when null.
final Color? tint;
final Color? selectedFill;
final Key? tapKey;
final VoidCallback? onTap;
final VoidCallback? onLongPress;
final bool selected;
final Widget child;
@override
State<_CupertinoRowSurface> createState() => _CupertinoRowSurfaceState();
}
class _CupertinoRowSurfaceState extends State<_CupertinoRowSurface> {
bool _pressed = false;
void _press(bool value) {
if (_pressed != value) setState(() => _pressed = value);
}
@override
Widget build(BuildContext context) {
final color = _pressed
? CupertinoColors.systemGrey4.resolveFrom(context)
: widget.selected
? widget.selectedFill ??
AppListRow.selectedColor(context, cupertino: true)
: widget.tint ?? const Color(0x00000000);
final enabled = widget.onTap != null;
return GestureDetector(
key: widget.tapKey,
behavior: HitTestBehavior.opaque,
onTap: widget.onTap,
onLongPress: widget.onLongPress,
onTapDown: enabled ? (_) => _press(true) : null,
onTapUp: enabled ? (_) => _press(false) : null,
onTapCancel: enabled ? () => _press(false) : null,
child: ColoredBox(
key: appListRowSurfaceKey,
color: color,
child: widget.child,
),
);
}
}
+13 -36
View File
@@ -1,19 +1,15 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
/// The label of every sheet's close action.
const appSheetDoneLabel = 'Done';
/// The app's one sheet header: the sheet's [title] at the start, then any
/// extra [actions] (Clear all), then Done, which closes the sheet.
///
/// Material shows the title in `titleLarge` and a [TextButton]; Cupertino
/// shows the navigation title style and a bold [CupertinoButton], like a
/// modal's navigation bar. The title is a header that names the route, so a
/// screen reader announces the sheet by it. Nothing has a fixed height and the
/// title wraps at large text. Used by the Runs filter and sort sheets and the
/// The title is shown in `titleLarge` with a [TextButton] for Done. The title
/// is a header that names the route, so a screen reader announces the sheet by
/// it. Nothing has a fixed height and the title wraps at large text. Used by the
/// Runs filter and sort sheets and the
/// Needs you sheet, so every sheet closes the same way, not only by its drag
/// handle.
class AppSheetHeader extends StatelessWidget {
@@ -28,46 +24,27 @@ class AppSheetHeader extends StatelessWidget {
final String title;
/// Controls before Done, in the host's style.
/// Controls before Done.
final List<Widget> actions;
/// Closes the sheet; the default pops the route the header is in.
final VoidCallback? onDone;
final Key? doneKey;
/// Overrides the host detection.
/// Ignored: the header is always Material. Kept so existing callers compile.
final bool? cupertino;
@override
Widget build(BuildContext context) {
final cupertino = this.cupertino ?? usesCupertinoHost(context);
final done = onDone ?? () => Navigator.of(context).maybePop();
final titleStyle = cupertino
? CupertinoTheme.of(context).textTheme.navTitleTextStyle
: Theme.of(context).textTheme.titleLarge;
final Widget doneButton = cupertino
? CupertinoButton(
key: doneKey,
padding: const EdgeInsets.symmetric(horizontal: 8),
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
onPressed: done,
child: const Text(
appSheetDoneLabel,
style: TextStyle(fontWeight: FontWeight.w600),
),
)
: TextButton(
key: doneKey,
onPressed: done,
child: const Text(appSheetDoneLabel),
);
final titleStyle = Theme.of(context).textTheme.titleLarge;
final Widget doneButton = TextButton(
key: doneKey,
onPressed: done,
child: const Text(appSheetDoneLabel),
);
return Padding(
padding: EdgeInsetsDirectional.fromSTEB(
cupertino ? 20 : 24,
cupertino ? 8 : 0,
8,
4,
),
padding: const EdgeInsetsDirectional.fromSTEB(24, 0, 8, 4),
child: LayoutBuilder(
builder: (context, constraints) {
final heading = Expanded(
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
import '../motion/motion.dart';
import 'section_heading.dart';
import 'sliver_animated_extent.dart';
@@ -90,10 +88,7 @@ class _SliverCollapsibleListSectionState
}
Widget _heading(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final muted = cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
final muted = Theme.of(context).colorScheme.onSurfaceVariant;
return Semantics(
container: true,
header: true,
@@ -123,10 +118,7 @@ class _SliverCollapsibleListSectionState
turns: _open ? 0.5 : 0,
duration: Motion.of(context, Motion.standard),
curve: Motion.curve,
child: Icon(
cupertino ? CupertinoIcons.chevron_down : Icons.expand_more,
color: muted,
),
child: Icon(Icons.expand_more, color: muted),
),
],
),
+11 -22
View File
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
import '../text/monospace.dart';
/// One recorded fact of a detail Summary: a small muted label over its value.
@@ -31,8 +29,8 @@ const int kFactsGridLongValue = 28;
/// The pane width from which the grid shows three facts per line.
const double kFactsGridThreeColumnWidth = 600;
/// A detail Summary's facts as one compact grid on the page, the same on
/// both hosts and in every detail (run, pipeline): two facts per line on a
/// A detail Summary's facts as one compact grid on the page, the same in every
/// detail (run, pipeline): two facts per line on a
/// phone, three from [kFactsGridThreeColumnWidth]; a long, wide or monospace
/// value (a path, a hash) takes a whole line.
///
@@ -51,28 +49,19 @@ class FactsGrid extends StatelessWidget {
final List<FactsGridItem> items;
final EdgeInsetsGeometry padding;
/// Material values are selectable text; Cupertino values stay plain text.
/// Values are selectable text unless this is false.
final bool selectable;
/// Overrides the host detection (a feature that picks its style per
/// platform).
/// Ignored: the grid is always Material. Kept so existing callers compile.
final bool? cupertino;
@override
Widget build(BuildContext context) {
final cupertino = this.cupertino ?? usesCupertinoHost(context);
final labelStyle = cupertino
? CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith(
color: CupertinoColors.secondaryLabel.resolveFrom(context),
)
: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
final labelStyle = Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
final TextStyle valueStyle =
(cupertino
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.bodyMedium) ??
const TextStyle();
Theme.of(context).textTheme.bodyMedium ?? const TextStyle();
return Padding(
padding: padding,
child: LayoutBuilder(
@@ -101,7 +90,7 @@ class FactsGrid extends StatelessWidget {
children: [
Text(item.label, style: labelStyle),
const SizedBox(height: 2),
_value(item, valueStyle, cupertino),
_value(item, valueStyle),
],
),
),
@@ -113,11 +102,11 @@ class FactsGrid extends StatelessWidget {
);
}
Widget _value(FactsGridItem item, TextStyle base, bool cupertino) {
Widget _value(FactsGridItem item, TextStyle base) {
final style = item.monospace
? base.copyWith(fontFamily: appMonospaceFamily)
: base;
if (cupertino || !selectable) return Text(item.value, style: style);
if (!selectable) return Text(item.value, style: style);
return SelectableText(item.value, style: style);
}
}
-23
View File
@@ -1,8 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
/// The look every section title shares: a quiet, grouped-list label rather than
/// another filled row.
class SectionHeadingStyle {
@@ -23,26 +20,6 @@ class SectionHeadingStyle {
final Color line;
static SectionHeadingStyle of(BuildContext context) {
if (usesCupertinoHost(context)) {
final theme = CupertinoTheme.of(context);
final base = theme.textTheme.textStyle;
// The detail pages (run, stage, pipeline) are flat on the page colour,
// as on Material, so a pinned heading's scrim is the page itself rather
// than a grey grouped band (black in dark mode).
final page = theme.scaffoldBackgroundColor;
return SectionHeadingStyle(
background: page,
body: page,
accent: CupertinoTheme.of(context).primaryColor,
title: base.copyWith(
fontSize: 13,
fontWeight: FontWeight.w600,
letterSpacing: 0.4,
color: CupertinoColors.secondaryLabel.resolveFrom(context),
),
line: CupertinoColors.separator.resolveFrom(context),
);
}
final scheme = Theme.of(context).colorScheme;
return SectionHeadingStyle(
background: scheme.surface,
+7 -33
View File
@@ -1,11 +1,8 @@
import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
import '../adaptive/window_margins.dart';
import '../theme/app_theme.dart';
import '../motion/motion.dart';
import 'section_heading.dart';
import 'sliver_reveal.dart';
@@ -179,13 +176,10 @@ class StickySectionTitle extends StatelessWidget {
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
// The shared section-title look is deliberately quiet, like a grouped-list
// label rather than a separate, filled row.
final heading = SectionHeadingStyle.of(context);
final muted = cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
final muted = Theme.of(context).colorScheme.onSurfaceVariant;
final style = color == null
? heading.title
: heading.title.copyWith(color: color);
@@ -193,10 +187,7 @@ class StickySectionTitle extends StatelessWidget {
turns: open ? 0.5 : 0,
duration: Motion.of(context, Motion.standard),
curve: Motion.curve,
child: Icon(
cupertino ? CupertinoIcons.chevron_down : Icons.expand_more,
color: muted,
),
child: Icon(Icons.expand_more, color: muted),
);
// On a wide window the chevron keeps the title's 16 px from the edge, in
// line with the top bar's trailing piece; a phone keeps it closer.
@@ -238,21 +229,10 @@ class StickySectionTitle extends StatelessWidget {
final scrim = pinned
? heading.background
: heading.background.withValues(alpha: 0.94);
final Widget strip = cupertino
? GestureDetector(
behavior: HitTestBehavior.opaque,
excludeFromSemantics: true,
onTap: onToggle,
child: ColoredBox(color: scrim, child: row),
)
: Material(
color: scrim,
child: InkWell(
onTap: onToggle,
excludeFromSemantics: true,
child: row,
),
);
final Widget strip = Material(
color: scrim,
child: InkWell(onTap: onToggle, excludeFromSemantics: true, child: row),
);
return Stack(
clipBehavior: Clip.none,
fit: StackFit.expand,
@@ -283,9 +263,6 @@ class _SectionBody extends StatelessWidget {
@override
Widget build(BuildContext context) {
final content = Padding(padding: padding, child: child);
if (usesCupertinoHost(context)) {
return content;
}
// Rows inside retain a Material ancestor for their ink reactions.
return Material(type: MaterialType.transparency, child: content);
}
@@ -300,12 +277,9 @@ class StickyBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
return PinnedHeaderSliver(
child: ColoredBox(
color: cupertino
? AppColors.groupedBackground.resolveFrom(context)
: Theme.of(context).colorScheme.surface,
color: Theme.of(context).colorScheme.surface,
child: child,
),
);
+1 -39
View File
@@ -1,8 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
import 'section_heading.dart';
/// Protocol warning arrays contain human-readable strings. Ignore malformed
@@ -37,43 +34,8 @@ class WarningsSection extends StatelessWidget {
for (final message in messages)
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 8),
child: usesCupertinoHost(context)
? _CupertinoWarningText(message)
: SelectableText(message),
child: SelectableText(message),
),
],
);
}
class _CupertinoWarningText extends StatefulWidget {
const _CupertinoWarningText(this.message);
final String message;
@override
State<_CupertinoWarningText> createState() => _CupertinoWarningTextState();
}
class _CupertinoWarningTextState extends State<_CupertinoWarningText> {
late final _controller = TextEditingController(text: widget.message);
@override
void didUpdateWidget(covariant _CupertinoWarningText oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.message != oldWidget.message) _controller.text = widget.message;
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => CupertinoTextField(
controller: _controller,
readOnly: true,
maxLines: null,
padding: EdgeInsets.zero,
decoration: const BoxDecoration(),
);
}
+147 -180
View File
@@ -1,6 +1,5 @@
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';
@@ -11,18 +10,10 @@ 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),
);
}
Widget _host(Widget child, {Brightness? brightness}) => MaterialApp(
theme: ThemeData(brightness: brightness ?? Brightness.light),
home: Scaffold(body: ListView(children: [child])),
);
void _size(WidgetTester tester, double width, {double textScale = 1}) {
tester.view.physicalSize = Size(width, 800);
@@ -79,187 +70,163 @@ 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('avatar, title with time, one line, menu, divider', (
tester,
) async {
_size(tester, 560);
var taps = 0;
String? picked;
await tester.pumpWidget(
_host(_row(onTap: () => taps++, onPicked: (value) => picked = value)),
);
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));
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);
await tester.tap(find.text('Fixture run'));
await tester.pumpAndSettle();
expect(taps, 1);
// The overflow control is a Material menu.
expect(
find.descendant(
of: find.byKey(const Key('menu')),
matching: find.byIcon(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');
expect(find.byType(PopupMenuItem<String>), findsNWidgets(2));
await tester.tap(find.byKey(const Key('menu-delete')));
await tester.pumpAndSettle();
expect(picked, 'delete');
});
// The overflow control is the same Material menu on every host.
expect(
find.descendant(
of: find.byKey(const Key('menu')),
matching: find.byIcon(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');
expect(find.byType(PopupMenuItem<String>), findsNWidgets(2));
await tester.tap(find.byKey(const Key('menu-delete')));
await tester.pumpAndSettle();
expect(picked, 'delete');
});
testWidgets('selected and emphasised rows', (tester) async {
_size(tester, 560);
await tester.pumpWidget(_host(_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(
tester.widget<Material>(surface).color,
AppListRow.selectedColor(context, cupertino: false),
);
final accent = Theme.of(context).colorScheme.primary;
expect(_paint(tester, 'Fixture run').fontWeight, FontWeight.w700);
expect(_paint(tester, '9d ago').color, accent);
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));
});
for (final width in [240.0, 270.0]) {
for (final brightness in Brightness.values) {
testWidgets('$host ${brightness.name}: a ${width.toInt()}px pane keeps '
'the status avatar and the menu, and the time under the subtitle', (
tester,
) async {
_size(tester, width);
await tester.pumpWidget(
_host(cupertino, brightness: brightness, _row(title: _longTitle)),
);
final row = tester.getRect(find.byKey(const Key('row')));
final avatar = tester.getRect(find.byKey(const Key('avatar')));
final menu = tester.getRect(find.byKey(const Key('menu')));
// Both inside the row, at the leading and trailing edges.
expect(avatar.left, greaterThanOrEqualTo(row.left));
expect(menu.right, lessThanOrEqualTo(row.right));
expect(menu.width, greaterThanOrEqualTo(44));
expect(menu.height, greaterThanOrEqualTo(44));
expect(find.text('Running'), findsOneWidget);
expect(find.text('pipeline · 2 stages'), findsNothing);
// The time sits on its own line, under the subtitle.
final time = tester.getRect(find.text('9d ago'));
final subtitle = tester.getRect(find.text('Running'));
expect(time.top, greaterThanOrEqualTo(subtitle.bottom));
expect(time.left, greaterThan(avatar.right));
expect(time.right, lessThan(menu.left));
// The title ellipsises between them.
final title = tester.getRect(find.text(_longTitle));
expect(title.left, greaterThan(avatar.right));
expect(title.right, lessThanOrEqualTo(menu.left));
expect(tester.takeException(), isNull);
});
}
}
await tester.pumpWidget(_host(_row()));
expect(tester.widget<Material>(surface).color, const Color(0x00000000));
expect(_paint(tester, '9d ago').color, isNot(accent));
});
for (final width in [240.0, 270.0]) {
for (final brightness in Brightness.values) {
testWidgets('$host ${brightness.name}: 320px at 2x text ellipsises '
'without overflow', (tester) async {
_size(tester, 320, textScale: 2);
testWidgets('${brightness.name}: a ${width.toInt()}px pane keeps '
'the status avatar and the menu, and the time under the subtitle', (
tester,
) async {
_size(tester, width);
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: (_, _) {},
),
),
),
_host(brightness: brightness, _row(title: _longTitle)),
);
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);
final avatar = tester.getRect(find.byKey(const Key('avatar')));
final menu = tester.getRect(find.byKey(const Key('menu')));
// Both inside the row, at the leading and trailing edges.
expect(avatar.left, greaterThanOrEqualTo(row.left));
expect(menu.right, lessThanOrEqualTo(row.right));
expect(menu.width, greaterThanOrEqualTo(44));
expect(menu.height, greaterThanOrEqualTo(44));
expect(find.text('Running'), findsOneWidget);
expect(find.text('pipeline · 2 stages'), findsNothing);
// The time sits on its own line, under the subtitle.
final time = tester.getRect(find.text('9d ago'));
final subtitle = tester.getRect(find.text('Running'));
expect(time.top, greaterThanOrEqualTo(subtitle.bottom));
expect(time.left, greaterThan(avatar.right));
expect(time.right, lessThan(menu.left));
// The title ellipsises between them.
final title = tester.getRect(find.text(_longTitle));
expect(title.left, greaterThan(avatar.right));
expect(title.right, lessThanOrEqualTo(menu.left));
expect(tester.takeException(), isNull);
});
}
}
for (final brightness in Brightness.values) {
testWidgets('${brightness.name}: 320px at 2x text ellipsises '
'without overflow', (tester) async {
_size(tester, 320, textScale: 2);
await tester.pumpWidget(
_host(
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 {
@@ -1,11 +1,8 @@
import 'package:flutter/cupertino.dart';
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 _app(Widget body) => MaterialApp(home: Scaffold(body: body));
Widget _list(ValueNotifier<int> rows) => ValueListenableBuilder<int>(
valueListenable: rows,
@@ -24,38 +21,36 @@ Widget _list(ValueNotifier<int> rows) => ValueListenableBuilder<int>(
);
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'reduced-motion groups accept asynchronous row changes without layout animation ($cupertino)',
(tester) async {
tester.platformDispatcher.accessibilityFeaturesTestValue =
const FakeAccessibilityFeatures(disableAnimations: true);
addTearDown(
tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
);
final rows = ValueNotifier<int>(1);
addTearDown(rows.dispose);
await tester.pumpWidget(_app(cupertino, _list(rows)));
await tester.pumpAndSettle();
rows.value = 3;
await tester.pump();
expect(find.text('Row 2'), findsOneWidget);
expect(tester.hasRunningAnimations, isFalse);
expect(tester.takeException(), isNull);
await tester.tap(find.text('Group'));
await tester.pump();
expect(find.text('Row 0'), findsNothing);
expect(tester.takeException(), isNull);
},
);
}
testWidgets(
'reduced-motion groups accept asynchronous row changes without layout animation',
(tester) async {
tester.platformDispatcher.accessibilityFeaturesTestValue =
const FakeAccessibilityFeatures(disableAnimations: true);
addTearDown(
tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
);
final rows = ValueNotifier<int>(1);
addTearDown(rows.dispose);
await tester.pumpWidget(_app(_list(rows)));
await tester.pumpAndSettle();
rows.value = 3;
await tester.pump();
expect(find.text('Row 2'), findsOneWidget);
expect(tester.hasRunningAnimations, isFalse);
expect(tester.takeException(), isNull);
await tester.tap(find.text('Group'));
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)));
await tester.pumpWidget(_app(_list(rows)));
double after() => tester.getTopLeft(find.text('After')).dy;
final top = after() - 80;
@@ -91,7 +86,7 @@ void main() {
) async {
final rows = ValueNotifier<int>(500);
addTearDown(rows.dispose);
await tester.pumpWidget(_app(false, _list(rows)));
await tester.pumpWidget(_app(_list(rows)));
expect(find.text('Row 0'), findsOneWidget);
expect(find.text('Row 100'), findsNothing);
});
+22 -31
View File
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart';
@@ -51,38 +50,30 @@ void main() {
},
);
for (final host in ['Material', 'Cupertino']) {
testWidgets('pins an opaque section edge below the top bar in $host', (
tester,
) async {
tester.view.physicalSize = const Size(390, 600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final child = MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(top: 64)),
child: _Host(),
);
await tester.pumpWidget(
host == 'Cupertino'
? CupertinoApp(home: child)
: MaterialApp(home: Scaffold(body: child)),
);
testWidgets('pins an opaque section edge below the top bar', (tester) async {
tester.view.physicalSize = const Size(390, 600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final child = MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(top: 64)),
child: _Host(),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: child)));
await tester.drag(find.byType(CustomScrollView), const Offset(0, -800));
await tester.pumpAndSettle();
await tester.drag(find.byType(CustomScrollView), const Offset(0, -800));
await tester.pumpAndSettle();
final title = tester.widget<StickySectionTitle>(
find.byType(StickySectionTitle),
);
expect(title.pinned, isTrue);
expect(
find.byWidgetPredicate(
(widget) => widget is Positioned && widget.top == -64,
),
findsOneWidget,
);
});
}
final title = tester.widget<StickySectionTitle>(
find.byType(StickySectionTitle),
);
expect(title.pinned, isTrue);
expect(
find.byWidgetPredicate(
(widget) => widget is Positioned && widget.top == -64,
),
findsOneWidget,
);
});
testWidgets('a tap anywhere on the title strip toggles the section', (
tester,