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
+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,