Merge: tabs as separate round glass buttons

This commit is contained in:
2026-11-02 18:44:27 +00:00
24 changed files with 916 additions and 1003 deletions
@@ -127,7 +127,7 @@ void main() {
);
expect(navigator.canPop(), isTrue);
expect(findNativeBack(), findsOneWidget);
expect(find.byType(NavigationBar), findsNothing);
expect(find.byType(FloatingDestinationBar), findsNothing);
await tester.pageBack();
await tester.pumpAndSettle();
@@ -4,7 +4,6 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_tabs.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_detail_styles.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
void main() {
testWidgets('code-like values still use native host typography', (
@@ -61,17 +60,14 @@ void main() {
),
);
await tester.pumpAndSettle();
// The host's own tab bar inside the shared glass pill.
expect(
find.byType(cupertino ? CupertinoTabBar : NavigationBar),
findsOneWidget,
);
final pill = tester.getRect(find.byType(GlassPill));
// One floating bar of separate round tab buttons.
expect(find.byType(FloatingDestinationBar), findsOneWidget);
final pill = tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
// Sized to its three tabs at the right edge, on a phone as when wide.
expect(pill.right, width - 16);
expect(
pill.width,
FloatingDestinationBar.pillWidth(
FloatingDestinationBar.rowWidth(
cupertino: cupertino,
tabs: PipelineDetailTab.values.length,
),
@@ -9,6 +9,7 @@ import 'package:pipelines_app/features/pipelines/pipeline_repository.dart';
import 'package:pipelines_app/features/pipelines/pipelines_controller.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_detail_panel.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'fixtures.dart';
import 'test_helpers.dart';
@@ -139,7 +140,7 @@ void main() {
expect(
find.descendant(
of: find.byKey(const Key('pipeline-detail-tabs')),
matching: find.byType(CupertinoTabBar),
matching: find.byType(FloatingDestinationBar),
),
findsOneWidget,
);
@@ -6,7 +6,6 @@ import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_tab_strip.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
import 'run_detail_graph_support.dart';
@@ -63,7 +62,10 @@ void main() {
// The tabs are the floating glass bar: on this 900px detail it is sized
// to its tabs at the right edge, above the bottom.
final pill = tester.getRect(
find.descendant(of: strip, matching: find.byType(GlassPill)),
find.descendant(
of: strip,
matching: find.byKey(FloatingDestinationBar.rowKey),
),
);
expect(pill.right, 900 - 16);
expect(pill.bottom, 1000 - 16);
@@ -89,13 +91,16 @@ void main() {
await pumpRunDetail(tester, platform, size: const Size(390, 844));
final strip = find.byKey(const Key('run-detail-tabs'));
final pill = tester.getRect(
find.descendant(of: strip, matching: find.byType(GlassPill)),
find.descendant(
of: strip,
matching: find.byKey(FloatingDestinationBar.rowKey),
),
);
final body = find.byKey(const Key('run-detail-tab-body-summary'));
// Sized to its tabs at the right, floating above the bottom.
expect(
pill.width,
FloatingDestinationBar.pillWidth(
FloatingDestinationBar.rowWidth(
cupertino: platform != RunDetailTestPlatform.material,
tabs: renderedRunDetailTabs.length,
),
@@ -125,7 +130,10 @@ void main() {
await pumpRunDetail(tester, platform, size: const Size(1000, 844));
final widePill = tester.getRect(
find.descendant(of: strip, matching: find.byType(GlassPill)),
find.descendant(
of: strip,
matching: find.byKey(FloatingDestinationBar.rowKey),
),
);
expect(widePill.right, 1000 - 16);
expect(widePill.bottom, 844 - 16);
@@ -6,7 +6,7 @@ import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart'
import 'package:pipelines_app/features/runs/ui/run_detail_visit_facts.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_visit_sections.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session_state.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'run_detail_graph_support.dart';
import 'run_detail_visit_support.dart';
@@ -241,7 +241,7 @@ void main() {
final pill = tester.getRect(
find.descendant(
of: find.byType(RunVisitSectionStrip),
matching: find.byType(GlassPill),
matching: find.byKey(FloatingDestinationBar.rowKey),
),
);
expect(pill.right, size.width - 16);
+3 -2
View File
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
/// The Runs tab mirrors the attention count in every mount of both hosts:
/// the floating tab bar at full width on a phone and right-aligned on a wide
@@ -35,7 +36,7 @@ void main() {
) async {
final semantics = tester.ensureSemantics();
await pumpShell(tester, width: width, cupertino: false, count: 3);
expect(find.byType(NavigationBar), findsOneWidget);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
expect(find.byType(NavigationRail), findsNothing);
final badge = find.byType(Badge);
expect(badge, findsOneWidget);
@@ -74,7 +75,7 @@ void main() {
) async {
final semantics = tester.ensureSemantics();
await pumpShell(tester, width: width, cupertino: true, count: 3);
expect(find.byType(CupertinoTabBar), findsOneWidget);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
expect(find.byType(Badge), findsNothing, reason: 'no Material badge');
expect(find.text('3'), findsOneWidget);
expect(find.bySemanticsLabel(needingAttention), findsOneWidget);
+5 -6
View File
@@ -4,14 +4,13 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
/// The shell's one floating glass tab bar: full width on a phone, sized to its
/// tabs at the right edge on a wide window, with content behind it.
void main() {
Finder pill() => find.descendant(
of: find.byType(FloatingDestinationBar),
matching: find.byType(GlassPill),
matching: find.byKey(FloatingDestinationBar.rowKey),
);
Future<void> setSize(WidgetTester tester, Size size) async {
@@ -56,7 +55,7 @@ void main() {
final rect = tester.getRect(pill());
expect(
rect.width,
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
);
expect(rect.right, 390 - 16);
expect(rect.bottom, 844 - 16);
@@ -81,7 +80,7 @@ void main() {
// Four icon-only tabs, with the wider neighbour gaps derived by the bar.
expect(
rect.width,
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
);
// No rail or sidebar: the content starts at the left edge.
expect(find.byType(NavigationRail), findsNothing);
@@ -135,7 +134,7 @@ void main() {
await tester.pump();
expect(
tester.getRect(pill()).width,
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
);
expect(tester.getRect(pill()).right, 390 - 16);
expect(tester.state(find.byType(StatefulBuilder)), same(state));
@@ -199,7 +198,7 @@ void main() {
// Sized to its four tabs at the right, as on any width.
expect(
tester.getRect(pill()).width,
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
);
expect(tester.getRect(pill()).right, 320 - 16);
}
+3 -3
View File
@@ -161,14 +161,14 @@ void main() {
find
.ancestor(
of: find.byKey(const ValueKey('shell.destination.runs')).first,
matching: find.byType(GlassPill),
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
final itemTabs = tester.getRect(
find.descendant(
of: find.byKey(const Key('item-tabs')),
matching: find.byType(GlassPill),
matching: find.byKey(FloatingDestinationBar.rowKey),
),
);
final body = tester.getRect(
@@ -214,7 +214,7 @@ void main() {
final tabs = tester.getRect(
find.descendant(
of: find.byKey(const Key('item-tabs')),
matching: find.byType(GlassPill),
matching: find.byKey(FloatingDestinationBar.rowKey),
),
);
expect(tabs.bottom, greaterThan(844 - 40));
+10 -8
View File
@@ -5,7 +5,6 @@ import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/shell_bar.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
Widget _app({required bool cupertino, required bool open, VoidCallback? back}) {
final shell = AdaptiveShell(
@@ -88,12 +87,12 @@ void main() {
final destinationPill = find.descendant(
of: find.byType(FloatingDestinationBar),
matching: find.byType(GlassPill),
matching: find.byKey(FloatingDestinationBar.rowKey),
);
// Sized to its four tabs at the bottom right.
expect(
tester.getSize(destinationPill).width,
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
);
expect(tester.getRect(destinationPill).right, 390 - 16);
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
@@ -154,7 +153,7 @@ void main() {
),
);
await tester.pumpWidget(shell());
expect(find.byType(NavigationBar), findsOneWidget);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
navigator.push(
MaterialPageRoute<void>(
@@ -162,13 +161,16 @@ void main() {
),
);
await tester.pumpAndSettle();
expect(find.byType(NavigationBar), findsNothing);
expect(find.byType(NavigationBar, skipOffstage: false), findsOneWidget);
expect(find.byType(FloatingDestinationBar), findsNothing);
expect(
find.byType(FloatingDestinationBar, skipOffstage: false),
findsOneWidget,
);
await navigator.maybePop();
await tester.pump(const Duration(milliseconds: 16));
expect(find.byType(NavigationBar), findsOneWidget);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
await tester.pumpAndSettle();
expect(find.byType(NavigationBar), findsOneWidget);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
},
);
}
@@ -6,7 +6,6 @@ import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/list_detail.dart';
import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
/// While a tab shows its list beside an open item, the shell's destination
/// bar keeps its place at the bottom right (near the thumb). The item's own
@@ -101,7 +100,7 @@ void main() {
find
.ancestor(
of: find.byKey(const ValueKey('shell.destination.chat')).first,
matching: find.byType(GlassPill),
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
@@ -160,7 +159,7 @@ void main() {
find
.descendant(
of: find.byKey(const Key('detail-tabs')),
matching: find.byType(GlassPill),
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
@@ -200,7 +199,7 @@ void main() {
final pill = destinationPill(tester);
expect(
pill.width,
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
);
expect(pill.right, closeTo(390 - kFloatingBarMargin, 0.5));
});
+6 -3
View File
@@ -10,7 +10,7 @@ import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/detail_page.dart';
import 'package:pipelines_app/shell/list_detail.dart';
import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import '../features/runs/ui/run_detail_graph_support.dart';
import '../features/runs/ui/run_detail_visit_support.dart';
@@ -21,14 +21,17 @@ import '../features/runs/ui/run_detail_visit_support.dart';
/// the detail pane instead of covering the shell.
void main() {
Rect pillOf(WidgetTester tester, Finder owner) => tester.getRect(
find.descendant(of: owner, matching: find.byType(GlassPill)).first,
find.descendant(
of: owner,
matching: find.byKey(FloatingDestinationBar.rowKey),
),
);
Rect shellPill(WidgetTester tester) => tester.getRect(
find
.ancestor(
of: find.byKey(const ValueKey('shell.destination.runs')).first,
matching: find.byType(GlassPill),
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
+7 -2
View File
@@ -171,14 +171,19 @@ void main() {
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
final tabs = pillsOf(tester, find.byKey(const Key('item-tabs'))).single;
final tabs = tester.getRect(
find.descendant(
of: find.byKey(const Key('item-tabs')),
matching: find.byKey(FloatingDestinationBar.rowKey),
),
);
expect(tabs.left, greaterThanOrEqualTo(body.left));
expect(tabs.right, lessThanOrEqualTo(body.right));
final shellTabs = tester.getRect(
find
.ancestor(
of: find.byKey(const ValueKey('shell.destination.runs')).first,
matching: find.byType(GlassPill),
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
@@ -1,368 +0,0 @@
import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
/// The floating tab bar is sized to its tabs at the bottom right on every
/// width, and its selection circle keeps one gap everywhere: the first and
/// last circles sit as far from the pill's sides as from its top and bottom,
/// and neighbouring circles are that far apart too, on both hosts.
void main() {
const icons = [
Icons.account_tree_outlined,
Icons.play_circle_outline,
Icons.chat_bubble_outline,
Icons.search,
Icons.settings_outlined,
];
Key tabKey(int index) => ValueKey('tab-$index');
Widget bar({
required bool cupertino,
required int count,
required int selected,
ValueChanged<int>? onTap,
}) => FloatingDestinationBar(
cupertino: cupertino,
currentIndex: selected,
onTap: onTap ?? (_) {},
items: [
for (var index = 0; index < count; index += 1)
FloatingDestinationItem(
key: tabKey(index),
icon: Icon(icons[index]),
label: 'Tab $index',
),
],
);
Future<void> pump(
WidgetTester tester, {
required bool cupertino,
required Size size,
required Widget child,
double textScale = 1,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final body = MediaQuery(
data: MediaQueryData(
size: size,
textScaler: TextScaler.linear(textScale),
),
child: child,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body)),
);
await tester.pumpAndSettle();
}
/// The bar's one selection highlight, at rest on tab [index].
Rect circle(WidgetTester tester, int index) {
final rect = tester.getRect(
find.descendant(
of: find.byKey(FloatingDestinationBar.highlightKey),
matching: find.byType(DecoratedBox),
),
);
final icon = tester.getCenter(
find.descendant(
of: find.byKey(tabKey(index)),
matching: find.byIcon(icons[index]),
),
);
expect(rect.center.dx, moreOrLessEquals(icon.dx, epsilon: 0.5));
expect(rect.center.dy, moreOrLessEquals(icon.dy, epsilon: 0.5));
return rect;
}
Rect pill(WidgetTester tester) => tester.getRect(
find.descendant(
of: find.byType(FloatingDestinationBar),
matching: find.byType(GlassPill),
),
);
final placements = [
(name: 'wide 1200, 4 tabs', size: const Size(1200, 800), count: 4),
(name: 'phone 390, 3 tabs', size: const Size(390, 844), count: 3),
(name: 'phone 390, 4 tabs', size: const Size(390, 844), count: 4),
(name: 'phone 560, 5 tabs', size: const Size(560, 844), count: 5),
(name: 'phone 320, 5 tabs', size: const Size(320, 640), count: 5),
];
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host: icon and selection circle sizes grow together', (
tester,
) async {
await pump(
tester,
cupertino: cupertino,
size: const Size(390, 844),
child: Align(
alignment: Alignment.bottomCenter,
child: bar(cupertino: cupertino, count: 2, selected: 0),
),
);
final icon = tester.getRect(find.byIcon(icons.first));
final mark = circle(tester, 0);
final iconSize = cupertino
? FloatingDestinationBar.cupertinoIconSize
: FloatingDestinationBar.materialIconSize;
final highlightSize = cupertino
? FloatingDestinationBar.cupertinoHighlightSize
: FloatingDestinationBar.materialHighlightSize;
expect(icon.width, iconSize);
expect(icon.height, iconSize);
expect(mark.width, highlightSize);
expect(mark.height, highlightSize);
});
testWidgets(
'$host: tab entrance animates once and respects reduced motion',
(tester) async {
tester.platformDispatcher.accessibilityFeaturesTestValue =
const FakeAccessibilityFeatures(disableAnimations: false);
addTearDown(() {
tester.platformDispatcher.accessibilityFeaturesTestValue =
const FakeAccessibilityFeatures(disableAnimations: true);
});
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
var selected = 0;
await tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(
child: MediaQuery(
data: const MediaQueryData(disableAnimations: false),
child: StatefulBuilder(
builder: (context, setState) => bar(
cupertino: cupertino,
count: 3,
selected: selected,
onTap: (index) => setState(() => selected = index),
),
),
),
),
)
: MaterialApp(
home: Scaffold(
body: MediaQuery(
data: const MediaQueryData(disableAnimations: false),
child: StatefulBuilder(
builder: (context, setState) => bar(
cupertino: cupertino,
count: 3,
selected: selected,
onTap: (index) => setState(() => selected = index),
),
),
),
),
),
);
Finder entranceOf(int index) => find
.descendant(
of: find.byKey(tabKey(index)),
matching: find.byWidgetPredicate(
(widget) =>
widget is FadeTransition && widget.child is AnimatedBuilder,
),
)
.last;
final entrance = entranceOf(0);
double firstOpacity() =>
tester.widget<FadeTransition>(entranceOf(0)).opacity.value;
double lastOpacity() =>
tester.widget<FadeTransition>(entranceOf(2)).opacity.value;
expect(firstOpacity(), 0);
expect(lastOpacity(), 0);
await tester.pump(const Duration(milliseconds: 130));
expect(firstOpacity(), greaterThan(0.9));
expect(lastOpacity(), lessThan(0.2));
await tester.pump(const Duration(milliseconds: 270));
expect(firstOpacity(), 1);
expect(lastOpacity(), 1);
await tester.tap(find.byKey(tabKey(1)));
await tester.pump();
await tester.pumpWidget(
MediaQuery(
data: const MediaQueryData(disableAnimations: true),
child: cupertino
? CupertinoApp(
home: CupertinoPageScaffold(
child: bar(cupertino: cupertino, count: 3, selected: 0),
),
)
: MaterialApp(
home: Scaffold(
body: bar(cupertino: cupertino, count: 3, selected: 0),
),
),
),
);
expect(tester.widget<FadeTransition>(entrance.first).opacity.value, 1);
},
);
for (final placement in placements) {
testWidgets('$host ${placement.name}: compact at the bottom right; the '
'outer circles keep the top gap from the sides and neighbours', (
tester,
) async {
final count = placement.count;
final size = placement.size;
final centres = <double>[];
for (final selected in [0, count - 1]) {
await pump(
tester,
cupertino: cupertino,
size: size,
child: Align(
alignment: Alignment.bottomCenter,
child: bar(
cupertino: cupertino,
count: count,
selected: selected,
),
),
);
final box = pill(tester);
expect(box.right, size.width - 16);
expect(box.bottom, size.height - 16);
final mark = circle(tester, selected);
expect(mark.width, mark.height);
final top = mark.top - box.top;
expect(box.bottom - mark.bottom, moreOrLessEquals(top, epsilon: 1));
final side = selected == 0
? mark.left - box.left
: box.right - mark.right;
expect(
side,
moreOrLessEquals(top, epsilon: 1),
reason: 'side gap $side vs top gap $top',
);
// The pill's round end is concentric with the outer circle.
expect(box.height / 2, moreOrLessEquals(top + mark.width / 2));
}
// Unselected icons sit where their circle would: neighbours are
// evenly spaced, with the larger named neighbour gap.
for (var index = 0; index < count; index += 1) {
centres.add(
tester
.getCenter(
find.descendant(
of: find.byKey(tabKey(index)),
matching: find.byIcon(icons[index]),
),
)
.dx,
);
}
final last = circle(tester, count - 1);
final box = pill(tester);
final edgeGap = last.top - box.top;
final requestedNeighbourGap = cupertino
? FloatingDestinationBar.cupertinoNeighbourGap
: FloatingDestinationBar.materialNeighbourGap;
final neighbourGap = math.min(
requestedNeighbourGap,
(box.width -
2 *
(cupertino
? FloatingDestinationBar.cupertinoEdgeGap
: FloatingDestinationBar.materialEdgeGap) -
count * last.width) /
(count - 1),
);
for (var index = 1; index < count; index += 1) {
expect(
centres[index] - centres[index - 1] - last.width,
moreOrLessEquals(neighbourGap, epsilon: 1),
);
}
expect(
neighbourGap - edgeGap,
moreOrLessEquals(
neighbourGap -
(cupertino
? FloatingDestinationBar.cupertinoEdgeGap
: FloatingDestinationBar.materialEdgeGap),
epsilon: 1,
),
);
expect(last.center.dx, moreOrLessEquals(centres.last, epsilon: 1));
});
}
testWidgets('$host phone: taps beside the compact bar reach the content, '
'taps on it the tabs', (tester) async {
final tapped = <int>[];
var content = 0;
await pump(
tester,
cupertino: cupertino,
size: const Size(390, 844),
child: Stack(
children: [
Positioned.fill(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => content++,
),
),
Align(
alignment: Alignment.bottomCenter,
child: bar(
cupertino: cupertino,
count: 3,
selected: 1,
onTap: tapped.add,
),
),
],
),
);
final box = pill(tester);
expect(box.width, lessThan(390 / 2));
await tester.tapAt(Offset(box.left - 40, box.center.dy));
await tester.tapAt(box.centerLeft + const Offset(12, 0));
await tester.tapAt(box.centerRight - const Offset(12, 0));
await tester.pump();
expect(content, 1);
expect(tapped, [0, 2]);
});
testWidgets('$host: 5 tabs at 320 with 2x text do not overflow', (
tester,
) async {
await pump(
tester,
cupertino: cupertino,
size: const Size(320, 640),
textScale: 2,
child: Align(
alignment: Alignment.bottomCenter,
child: bar(cupertino: cupertino, count: 5, selected: 4),
),
);
expect(tester.takeException(), isNull);
expect(pill(tester).right, 320 - 16);
expect(pill(tester).left, greaterThanOrEqualTo(16));
});
}
}
@@ -0,0 +1,254 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
/// The floating tab bar is a row of separate round glass buttons at the
/// bottom right on every width: each tab its own circle of the named size,
/// evenly spaced, the row keeping the margins from the edges, on both hosts.
void main() {
const icons = [
Icons.account_tree_outlined,
Icons.play_circle_outline,
Icons.chat_bubble_outline,
Icons.search,
Icons.settings_outlined,
];
Key tabKey(int index) => ValueKey('tab-$index');
Widget bar({
required bool cupertino,
required int count,
required int selected,
ValueChanged<int>? onTap,
}) => FloatingDestinationBar(
cupertino: cupertino,
currentIndex: selected,
onTap: onTap ?? (_) {},
items: [
for (var index = 0; index < count; index += 1)
FloatingDestinationItem(
key: tabKey(index),
icon: Icon(icons[index]),
label: 'Tab $index',
),
],
);
Future<void> pump(
WidgetTester tester, {
required bool cupertino,
required Size size,
required Widget child,
double textScale = 1,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final body = MediaQuery(
data: MediaQueryData(
size: size,
textScaler: TextScaler.linear(textScale),
),
child: child,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body)),
);
await tester.pumpAndSettle();
}
/// Tab [index]'s glass circle.
Rect button(WidgetTester tester, int index) => tester.getRect(
find.descendant(
of: find.byKey(tabKey(index)),
matching: find.byType(GlassPill),
),
);
Rect row(WidgetTester tester) =>
tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
final placements = [
(name: 'wide 1200, 4 tabs', size: const Size(1200, 800), count: 4),
(name: 'phone 390, 3 tabs', size: const Size(390, 844), count: 3),
(name: 'phone 390, 4 tabs', size: const Size(390, 844), count: 4),
(name: 'phone 560, 5 tabs', size: const Size(560, 844), count: 5),
];
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
final diameter = FloatingDestinationBar.buttonSize(cupertino: cupertino);
final gap = FloatingDestinationBar.buttonGap(cupertino: cupertino);
final iconSize = cupertino
? FloatingDestinationBar.cupertinoIconSize
: FloatingDestinationBar.materialIconSize;
test('$host: buttons are larger than the old 44/42 circle, hit targets '
'meet the platform minimum', () {
expect(diameter, cupertino ? 50 : 52);
expect(diameter, greaterThanOrEqualTo(cupertino ? 44 : 48));
expect(gap, inInclusiveRange(10, 12));
});
testWidgets('$host: each tab is its own glass circle with the icon '
'centred in it', (tester) async {
await pump(
tester,
cupertino: cupertino,
size: const Size(390, 844),
child: Align(
alignment: Alignment.bottomCenter,
child: bar(cupertino: cupertino, count: 3, selected: 0),
),
);
expect(
find.descendant(
of: find.byType(FloatingDestinationBar),
matching: find.byType(GlassPill),
),
findsNWidgets(3),
);
for (var index = 0; index < 3; index += 1) {
final circle = button(tester, index);
expect(circle.size, Size(diameter, diameter));
expect(
tester
.widget<GlassPill>(
find.descendant(
of: find.byKey(tabKey(index)),
matching: find.byType(GlassPill),
),
)
.shape,
isA<CircleBorder>(),
);
final icon = tester.getRect(find.byIcon(icons[index]));
expect(icon.size, Size(iconSize, iconSize));
expect(icon.center, circle.center);
}
});
for (final placement in placements) {
testWidgets('$host ${placement.name}: a row at the bottom right, '
'evenly spaced', (tester) async {
final count = placement.count;
final size = placement.size;
await pump(
tester,
cupertino: cupertino,
size: size,
child: Align(
alignment: Alignment.bottomCenter,
child: bar(cupertino: cupertino, count: count, selected: 0),
),
);
final box = row(tester);
expect(box.right, size.width - 16);
expect(box.bottom, size.height - 16);
expect(box.height, diameter);
expect(
box.width,
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: count),
);
expect(button(tester, 0).left, box.left);
expect(button(tester, count - 1).right, box.right);
for (var index = 1; index < count; index += 1) {
expect(
button(tester, index).left - button(tester, index - 1).right,
moreOrLessEquals(gap),
);
expect(button(tester, index).top, box.top);
}
});
}
testWidgets('$host: taps between and beside the buttons reach the '
'content, taps on them the tabs', (tester) async {
final tapped = <int>[];
var content = 0;
await pump(
tester,
cupertino: cupertino,
size: const Size(390, 844),
child: Stack(
children: [
Positioned.fill(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => content++,
),
),
Align(
alignment: Alignment.bottomCenter,
child: bar(
cupertino: cupertino,
count: 3,
selected: 1,
onTap: tapped.add,
),
),
],
),
);
final box = row(tester);
expect(box.width, lessThan(390 / 2));
await tester.tapAt(Offset(box.left - 40, box.center.dy));
final between = (button(tester, 0).right + button(tester, 1).left) / 2;
await tester.tapAt(Offset(between, box.center.dy));
await tester.tapAt(button(tester, 0).center);
await tester.tapAt(button(tester, 2).center);
await tester.pumpAndSettle();
expect(content, 2);
expect(tapped, [0, 2]);
});
testWidgets('$host: 5 tabs at 320 with 2x text narrow their gaps and '
'stay within the margins', (tester) async {
await pump(
tester,
cupertino: cupertino,
size: const Size(320, 640),
textScale: 2,
child: Align(
alignment: Alignment.bottomCenter,
child: bar(cupertino: cupertino, count: 5, selected: 4),
),
);
expect(tester.takeException(), isNull);
final box = row(tester);
expect(box.right, 320 - 16);
expect(box.left, greaterThanOrEqualTo(16));
final narrowed = (288 - 5 * diameter) / 4;
for (var index = 1; index < 5; index += 1) {
expect(button(tester, index).width, diameter);
expect(
button(tester, index).left - button(tester, index - 1).right,
moreOrLessEquals(narrowed < gap ? narrowed : gap),
);
}
});
testWidgets('$host: right to left, the row sits at the bottom left and '
'reads from the right', (tester) async {
await pump(
tester,
cupertino: cupertino,
size: const Size(390, 844),
child: Directionality(
textDirection: TextDirection.rtl,
child: Align(
alignment: Alignment.bottomCenter,
child: bar(cupertino: cupertino, count: 3, selected: 0),
),
),
);
expect(row(tester).left, 16);
expect(button(tester, 0).right, row(tester).right);
});
}
}
@@ -49,7 +49,7 @@ void main() {
),
),
);
final pill = tester.getRect(find.byType(GlassPill));
final pill = tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
// The list fills the area, behind the bar.
expect(tester.getRect(find.byType(ListView)).bottom, 800);
await tester.drag(find.byType(ListView), const Offset(0, -5000));
@@ -67,11 +67,11 @@ void main() {
await tester.pumpWidget(
page(list: (_) => const SizedBox.expand(), onTap: () => taps++),
);
final pill = tester.getRect(find.byType(GlassPill));
final pill = tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
expect(pill.right, 1200 - kFloatingBarMargin);
await tester.tapAt(Offset(pill.left - 24, pill.center.dy));
expect(taps, 1);
await tester.tapAt(pill.center);
await tester.tapAt(tester.getCenter(find.byType(GlassPill).first));
expect(taps, 1, reason: 'the bar takes its own taps');
});
}
+162 -137
View File
@@ -4,10 +4,13 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'package:pipelines_app/ui/adaptive/floating_tab_button.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
/// The floating tab bar's motion: the tabs pop in only when the bar appears
/// or its set of tabs changes, and one selection highlight glides (and
/// stretches on the way) to a newly selected tab, whose icon bounces.
/// The floating tab bar's motion: each button pops in on its own, staggered,
/// only when the bar appears or its set of tabs changes; the selection tint
/// cross-fades to a newly selected button, whose icon bounces; a press sinks
/// the button and it springs back.
void main() {
const icons = [
Icons.account_tree_outlined,
@@ -30,15 +33,16 @@ void main() {
void animate(WidgetTester tester, {required bool on}) {
tester.platformDispatcher.accessibilityFeaturesTestValue =
FakeAccessibilityFeatures(disableAnimations: !on);
addTearDown(() {
tester.platformDispatcher.accessibilityFeaturesTestValue =
const FakeAccessibilityFeatures(disableAnimations: true);
});
addTearDown(tester.platformDispatcher.clearAccessibilityFeaturesTestValue);
tester.view.physicalSize = const Size(560, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
}
Widget app(bool cupertino, Widget body) => cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body));
/// A bar of [count] tabs whose tap selects.
Future<void> pumpBar(
WidgetTester tester, {
@@ -46,74 +50,92 @@ void main() {
int count = 3,
}) async {
var selected = 0;
final body = StatefulBuilder(
builder: (context, setState) {
return Align(
alignment: Alignment.bottomCenter,
child: FloatingDestinationBar(
cupertino: cupertino,
currentIndex: selected,
onTap: (index) => setState(() => selected = index),
items: items(count),
),
);
},
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body)),
app(
cupertino,
StatefulBuilder(
builder: (context, setState) => Align(
alignment: Alignment.bottomCenter,
child: FloatingDestinationBar(
cupertino: cupertino,
currentIndex: selected,
onTap: (index) => setState(() => selected = index),
items: items(count),
),
),
),
),
);
}
/// The opacity of [tab]'s entrance fade.
double opacityOf(WidgetTester tester, Finder tab) => tester
.widget<FadeTransition>(
find
.descendant(
of: tab,
matching: find.byWidgetPredicate(
(widget) =>
widget is FadeTransition && widget.child is AnimatedBuilder,
),
)
.last,
)
.opacity
.value;
Finder glass(Finder tab) =>
find.descendant(of: tab, matching: find.byType(GlassPill));
double iconWidth(WidgetTester tester, Finder tab, IconData icon) => tester
.getRect(find.descendant(of: tab, matching: find.byIcon(icon)))
/// The opacity of [tab]'s entrance fade (its glass reveal).
double opacityOf(WidgetTester tester, Finder tab) =>
GlassReveal.maybeOf(tester.element(glass(tab)))?.value ?? 1;
/// [tab]'s drawn width (its entrance and press scale it).
double widthOf(WidgetTester tester, Finder tab) =>
tester.getRect(glass(tab)).width;
double iconWidth(WidgetTester tester, int index) => tester
.getRect(
find.descendant(
of: find.byKey(tabKey(index)),
matching: find.byIcon(icons[index]),
),
)
.width;
Rect highlight(WidgetTester tester) => tester.getRect(
find.descendant(
of: find.byKey(FloatingDestinationBar.highlightKey),
matching: find.byType(DecoratedBox),
),
);
Offset iconCentre(WidgetTester tester, int index) => tester.getCenter(
find.descendant(
of: find.byKey(tabKey(index)),
matching: find.byIcon(icons[index]),
),
);
/// The alpha of tab [index]'s selection fill.
double fillAlpha(WidgetTester tester, int index) {
final fill = tester.widget(
find.descendant(
of: find.byKey(tabKey(index)),
matching: find.byKey(FloatingTabButton.fillKey),
),
);
final decoration = fill is Ink
? fill.decoration
: (fill as DecoratedBox).decoration;
return (decoration! as ShapeDecoration).color!.a;
}
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
final size = FloatingDestinationBar.buttonSize(cupertino: cupertino);
final iconSize = cupertino
? FloatingDestinationBar.cupertinoIconSize
: FloatingDestinationBar.materialIconSize;
final size = cupertino
? FloatingDestinationBar.cupertinoHighlightSize
: FloatingDestinationBar.materialHighlightSize;
testWidgets('$host: the entrance does not replay when the selection '
'changes, and plays again for a new set of tabs', (tester) async {
testWidgets('$host: each button pops in on its own, staggered, from '
'0.6 to full size', (tester) async {
animate(tester, on: true);
await pumpBar(tester, cupertino: cupertino);
for (var index = 0; index < 3; index += 1) {
final tab = find.byKey(tabKey(index));
expect(opacityOf(tester, tab), 0);
expect(widthOf(tester, tab), moreOrLessEquals(size * 0.6));
}
await tester.pump(const Duration(milliseconds: 130));
final first = widthOf(tester, find.byKey(tabKey(0)));
final last = widthOf(tester, find.byKey(tabKey(2)));
expect(first, greaterThan(last + 4), reason: 'staggered');
expect(opacityOf(tester, find.byKey(tabKey(0))), greaterThan(0.9));
expect(opacityOf(tester, find.byKey(tabKey(2))), lessThan(0.2));
await tester.pumpAndSettle();
for (var index = 0; index < 3; index += 1) {
final tab = find.byKey(tabKey(index));
expect(opacityOf(tester, tab), 1);
expect(widthOf(tester, tab), size);
}
});
testWidgets('$host: the entrance does not replay when the selection '
'changes', (tester) async {
animate(tester, on: true);
await pumpBar(tester, cupertino: cupertino);
expect(opacityOf(tester, find.byKey(tabKey(0))), 0);
await tester.pumpAndSettle();
for (final target in [1, 2, 0]) {
await tester.tap(find.byKey(tabKey(target)));
@@ -122,14 +144,18 @@ void main() {
for (var index = 0; index < 3; index += 1) {
final tab = find.byKey(tabKey(index));
expect(opacityOf(tester, tab), 1, reason: 'tab $index faded');
// Only the bounce may grow an icon; a replayed pop shrinks it.
// Only the press may shrink the tapped button, and only a
// little; a replayed pop starts at 0.6.
expect(
iconWidth(tester, tab, icons[index]),
greaterThanOrEqualTo(iconSize - 0.01),
widthOf(tester, tab),
index == target
? greaterThan(size * 0.9)
: moreOrLessEquals(size),
reason: 'tab $index popped again',
);
}
}
await tester.pumpAndSettle();
}
});
@@ -137,24 +163,24 @@ void main() {
animate(tester, on: true);
var count = 3;
late StateSetter update;
Widget build() => StatefulBuilder(
builder: (context, setState) {
update = setState;
return Align(
alignment: Alignment.bottomCenter,
child: FloatingDestinationBar(
cupertino: cupertino,
currentIndex: 0,
onTap: (_) {},
items: items(count),
),
);
},
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: build()))
: MaterialApp(home: Scaffold(body: build())),
app(
cupertino,
StatefulBuilder(
builder: (context, setState) {
update = setState;
return Align(
alignment: Alignment.bottomCenter,
child: FloatingDestinationBar(
cupertino: cupertino,
currentIndex: 0,
onTap: (_) {},
items: items(count),
),
);
},
),
),
);
await tester.pumpAndSettle();
expect(opacityOf(tester, find.byKey(tabKey(2))), 1);
@@ -164,84 +190,80 @@ void main() {
expect(opacityOf(tester, find.byKey(tabKey(2))), 0);
await tester.pumpAndSettle();
expect(opacityOf(tester, find.byKey(tabKey(3))), 1);
expect(widthOf(tester, find.byKey(tabKey(3))), size);
});
testWidgets('$host: the highlight rests on the selected tab as the old '
'circle did, glides and stretches between tabs, and the new icon '
'bounces', (tester) async {
testWidgets('$host: the selection tint cross-fades to the new button, '
'whose icon takes the selected colour and bounces', (tester) async {
animate(tester, on: true);
await pumpBar(tester, cupertino: cupertino);
await tester.pumpAndSettle();
expect(
highlight(tester),
rectMoreOrLessEquals(
Rect.fromCenter(
center: iconCentre(tester, 0),
width: size,
height: size,
),
epsilon: 0.01,
),
);
expect(find.byKey(FloatingDestinationBar.highlightKey), findsOneWidget);
final tint = fillAlpha(tester, 0);
expect(tint, greaterThan(0.1));
expect(fillAlpha(tester, 1), 0);
expect(fillAlpha(tester, 2), 0);
await tester.tap(find.byKey(tabKey(2)));
await tester.pump();
await tester.pump(const Duration(milliseconds: 60));
final from = iconCentre(tester, 0).dx;
final to = iconCentre(tester, 2).dx;
final moving = highlight(tester);
expect(moving.center.dx, greaterThan(from + 1));
expect(moving.center.dx, lessThan(to - 1));
expect(moving.height, moreOrLessEquals(size));
expect(moving.width, greaterThan(size * 1.1));
expect(moving.width, lessThanOrEqualTo(size * 1.25 + 0.01));
await tester.pump(const Duration(milliseconds: 80));
expect(fillAlpha(tester, 2), inExclusiveRange(0, tint));
expect(fillAlpha(tester, 0), inExclusiveRange(0, tint));
// The icon grows within its button (which the tap's press sinks).
expect(
iconWidth(tester, find.byKey(tabKey(2)), icons[2]),
greaterThan(iconSize * 1.02),
iconWidth(tester, 2) * size / widthOf(tester, find.byKey(tabKey(2))),
greaterThan(iconSize * 1.04),
);
expect(iconWidth(tester, 1), moreOrLessEquals(iconSize));
await tester.pumpAndSettle();
expect(fillAlpha(tester, 2), tint);
expect(fillAlpha(tester, 0), 0);
expect(iconWidth(tester, 2), moreOrLessEquals(iconSize));
final context = tester.element(find.byKey(tabKey(2)));
final selectedColour = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.onSecondaryContainer;
expect(
highlight(tester),
rectMoreOrLessEquals(
Rect.fromCenter(
center: iconCentre(tester, 2),
width: size,
height: size,
),
epsilon: 0.01,
),
IconTheme.of(tester.element(find.byIcon(icons[2]))).color,
isSameColorAs(selectedColour),
);
expect(
iconWidth(tester, find.byKey(tabKey(2)), icons[2]),
moreOrLessEquals(iconSize),
IconTheme.of(tester.element(find.byIcon(icons[0]))).color,
isNot(isSameColorAs(selectedColour)),
);
});
testWidgets('$host: under reduced motion the highlight jumps and the '
'icons neither pop nor bounce', (tester) async {
testWidgets('$host: a press sinks the button and it springs back', (
tester,
) async {
animate(tester, on: true);
await pumpBar(tester, cupertino: cupertino);
await tester.pumpAndSettle();
final tab = find.byKey(tabKey(1));
final gesture = await tester.startGesture(tester.getCenter(tab));
await tester.pump();
await tester.pump(const Duration(milliseconds: 120));
expect(widthOf(tester, tab), lessThan(size * 0.97));
expect(widthOf(tester, find.byKey(tabKey(0))), size);
await gesture.up();
await tester.pumpAndSettle();
expect(widthOf(tester, tab), size);
});
testWidgets('$host: under reduced motion the tint jumps and the buttons '
'neither pop nor bounce', (tester) async {
animate(tester, on: false);
await pumpBar(tester, cupertino: cupertino);
await tester.pump();
expect(opacityOf(tester, find.byKey(tabKey(1))), 1);
expect(widthOf(tester, find.byKey(tabKey(1))), size);
final tint = fillAlpha(tester, 0);
await tester.tap(find.byKey(tabKey(2)));
await tester.pump();
expect(
highlight(tester),
rectMoreOrLessEquals(
Rect.fromCenter(
center: iconCentre(tester, 2),
width: size,
height: size,
),
epsilon: 0.01,
),
);
expect(
iconWidth(tester, find.byKey(tabKey(2)), icons[2]),
moreOrLessEquals(iconSize),
);
await tester.pump();
expect(fillAlpha(tester, 2), tint);
expect(fillAlpha(tester, 0), 0);
expect(iconWidth(tester, 2), moreOrLessEquals(iconSize));
});
testWidgets('$host: switching the shell tabs never replays the main '
@@ -270,14 +292,17 @@ void main() {
for (var frame = 0; frame < 12; frame += 1) {
await tester.pump(const Duration(milliseconds: 25));
for (final tab in shellTabDestinations) {
final finder = find.byKey(
ValueKey('shell.destination.${tab.name}'),
);
expect(
opacityOf(
tester,
find.byKey(ValueKey('shell.destination.${tab.name}')),
),
opacityOf(tester, finder),
1,
reason: '${tab.name} faded switching to ${next.name}',
);
if (tab != next) {
expect(widthOf(tester, finder), size, reason: tab.name);
}
}
}
await tester.pumpAndSettle();
@@ -1,3 +1,5 @@
import 'dart:ui' show SemanticsRole;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -63,32 +65,58 @@ void main() {
await tester.pumpAndSettle();
final floating = find.byType(FloatingDestinationBar);
if (cupertino) {
// No label is drawn at all.
expect(
find.descendant(of: floating, matching: find.byType(Text)),
findsNothing,
);
} else {
// NavigationBar keeps its label hidden (for semantics only).
expect(
NavigationBarTheme.of(
tester.element(find.byType(NavigationDestination).first),
).labelBehavior,
NavigationDestinationLabelBehavior.alwaysHide,
);
}
// No label is drawn at all.
expect(
find.descendant(of: floating, matching: find.byType(Text)),
findsNothing,
);
for (final (index, (key, tabLabel)) in tabs.indexed) {
final node = tester.getSemantics(find.byKey(ValueKey(key)));
final finder = find.byKey(ValueKey(key));
final node = tester.getSemantics(finder);
expect(node.label, startsWith(tabLabel), reason: key);
expect(
node,
index == 0
? isSemantics(isSelected: true)
: isNot(isSemantics(isSelected: true)),
isSemantics(
isSelected: index == 0,
hasSelectedState: true,
isButton: true,
hasTapAction: true,
),
reason: key,
);
expect(node.role, SemanticsRole.tab, reason: key);
// "Tab n of m", as the host navigation controls announce it: in the
// Material label, the Cupertino hint.
final position = 'Tab ${index + 1} of ${tabs.length}';
expect(
cupertino ? node.hint : node.label,
contains(position),
reason: key,
);
// Material names the tab in its tooltip too.
if (!cupertino) {
expect(
find.descendant(
of: finder,
matching: find.byWidgetPredicate(
(widget) => widget is Tooltip && widget.message == tabLabel,
),
),
findsOneWidget,
reason: key,
);
}
// A hit target at least the platform minimum.
expect(
tester.getSize(finder).shortestSide,
greaterThanOrEqualTo(cupertino ? 44 : 48),
);
}
// The tabs make up one tab bar.
final tabBar = tester.getSemantics(
find.byKey(FloatingDestinationBar.rowKey),
);
expect(tabBar.role, SemanticsRole.tabBar);
// Distinct glyphs within the bar.
final icons = tester
.widgetList<Icon>(
@@ -184,10 +184,10 @@ void main() {
),
),
);
final pill = tester.getRect(find.byType(GlassPill));
final pill = tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
expect(pill.top, 64);
// The pill is the bar's own height: leftover media padding is not added.
expect(pill.height, FloatingDestinationBar.materialHeight);
expect(pill.height, FloatingDestinationBar.materialButtonSize);
// Wide: sized to its tabs at the leading edge, under the title.
expect(pill.left, FloatingDestinationBar.topMargin);
expect(pill.width, lessThan(400));
+5 -4
View File
@@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/main.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
void main() {
for (final width in [390.0, 1000.0]) {
@@ -25,7 +26,7 @@ void main() {
expect(find.text('Pipelines'), findsWidgets);
expect(find.text('Pipelines — Not implemented'), findsOneWidget);
// One floating tab bar at every width; no rail.
expect(find.byType(NavigationBar), findsOneWidget);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
expect(find.byType(NavigationRail), findsNothing);
expect(tester.takeException(), isNull);
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
@@ -45,7 +46,7 @@ void main() {
await tester.pumpWidget(const MyApp(cupertino: true));
expect(find.byType(SegmentedBar), findsOneWidget);
expect(find.byType(CupertinoNavigationBar), findsNothing);
expect(find.byType(CupertinoTabBar), findsOneWidget);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
expect(find.text('Pipelines — Not implemented'), findsOneWidget);
});
@@ -57,7 +58,7 @@ void main() {
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(const MyApp(cupertino: true));
expect(find.byType(CupertinoTabBar), findsOneWidget);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
expect(find.byType(CupertinoListTile), findsNothing);
expect(
find.byKey(const ValueKey('shell.destination.pipelines')),
@@ -76,7 +77,7 @@ void main() {
tester.view.padding = const FakeViewPadding(top: 36, bottom: 28);
addTearDown(tester.view.resetPadding);
await tester.pumpWidget(const MyApp(cupertino: true));
final tabBar = tester.getRect(find.byType(CupertinoTabBar));
final tabBar = tester.getRect(find.byType(FloatingDestinationBar));
expect(tabBar.bottom, lessThanOrEqualTo(900 - 28));
expect(tester.takeException(), isNull);
});