Add phone bottom navigation bar

Replace the narrow-layout floating destination pill with a full-width Material 3 NavigationBar. Reuse the shell destination model and badge wiring while preserving re-selection callbacks and hiding the bar for keyboard/detail states.
This commit is contained in:
2026-11-12 02:51:01 +00:00
parent 9bb87e5118
commit aabd22b5ad
12 changed files with 467 additions and 126 deletions
+43 -34
View File
@@ -3,13 +3,14 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/list_detail_policy.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/shell_navigation_bar.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_labels.dart';
import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart';
/// Main navigation keeps visible captions and full-size targets, floating at
/// the trailing edge on a phone and the leading edge under the list on a wide
/// window.
/// Main navigation keeps visible captions and full-size targets: a full-width
/// navigation bar on a phone, and on a wide window a floating bar at the
/// leading edge under the list.
void main() {
Finder pill() => find.descendant(
of: find.byType(FloatingDestinationBar),
@@ -87,19 +88,18 @@ void main() {
return MaterialApp(home: app);
}
testWidgets('phone bar hugs its tabs at the bottom right too, and '
'taps beside it reach the content', (tester) async {
testWidgets('a phone shows a full-width navigation bar, and taps above it '
'reach the content', (tester) async {
taps = 0;
await setSize(tester, const Size(390, 844));
await tester.pumpWidget(shell());
final rect = tester.getRect(pill());
await expectLabeledTargets(tester, rect);
await expectNoSharedBackdrop(tester);
expect(rect.width, lessThanOrEqualTo(390 - 2 * 16));
expect(rect.right, 390 - 16);
expect(rect.bottom, 844 - 16);
await tester.pumpAndSettle();
final bar = tester.getRect(find.byType(NavigationBar));
expect(bar.left, 0);
expect(bar.right, 390);
expect(find.byType(FloatingDestinationBar), findsNothing);
expect(find.byType(NavigationRail), findsNothing);
await tester.tapAt(Offset(rect.left - 40, rect.center.dy));
await tester.tapAt(Offset(195, bar.top - 40));
await tester.pump();
expect(taps, 1);
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
@@ -146,7 +146,9 @@ void main() {
await setSize(tester, size);
await tester.pumpWidget(shell());
await tester.pump();
final rect = tester.getRect(pill());
final rect = size.width < 600
? tester.getRect(find.byType(NavigationBar))
: tester.getRect(pill());
// The content's bottom padding clears the whole bar and its margin.
expect(
contentBottomPadding,
@@ -169,6 +171,7 @@ void main() {
tester.view.physicalSize = const Size(640, 800);
await tester.pump();
expect(find.byType(NavigationBar), findsNothing);
expect(
tester.getRect(pill()).left,
moreOrLessEquals(kFloatingBarMargin, epsilon: 0.5),
@@ -178,17 +181,21 @@ void main() {
tester.view.physicalSize = const Size(390, 844);
await tester.pump();
await expectLabeledTargets(tester, tester.getRect(pill()));
expect(tester.getRect(pill()).width, lessThanOrEqualTo(390 - 2 * 16));
expect(tester.getRect(pill()).right, 390 - 16);
await tester.pumpAndSettle();
expect(find.byType(FloatingDestinationBar), findsNothing);
expect(tester.getRect(find.byType(NavigationBar)).width, 390);
expect(tester.state(find.byType(StatefulBuilder)), same(state));
});
testWidgets('the bar respects the bottom safe area', (tester) async {
testWidgets('the navigation bar respects the bottom safe area', (
tester,
) async {
await setSize(tester, const Size(390, 844));
tester.view.padding = const FakeViewPadding(bottom: 34);
await tester.pumpWidget(shell());
expect(tester.getRect(pill()).bottom, 844 - 34);
await tester.pumpAndSettle();
// The bar sits above the gesture inset, its own surface ending there.
expect(tester.getRect(find.byType(NavigationBar)).bottom, 844 - 34);
});
testWidgets('the selected tab is marked selected for assistive '
@@ -218,23 +225,25 @@ void main() {
await tester.pumpWidget(shell());
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
// Large captions wrap rather than shrinking the tap targets.
final bounds = tester.getRect(pill());
await expectLabeledTargets(tester, bounds);
expect(bounds.width, lessThanOrEqualTo(320 - 2 * 16));
for (final destination in shellTabDestinations) {
final caption = find.descendant(
of: find.byType(FloatingDestinationBar),
matching: find.text(destinationDetails(destination).label),
final bar = find.byType(NavigationBar);
expect(tester.getRect(bar).width, 320);
// Every destination keeps its label and a full-size target at 2x text.
for (final destination in shellBarDestinations) {
final label = destinationDetails(destination).label;
final caption = find.descendant(of: bar, matching: find.text(label));
expect(caption, findsOneWidget);
expect(
tester.getRect(caption).overlaps(tester.getRect(bar)),
isTrue,
reason: label,
);
final text = tester.widget<Text>(caption);
final size = text.style!.fontSize!;
expect(tester.getSize(caption).height, greaterThanOrEqualTo(size * 2));
final target = tester.getSize(
find.byType(NavigationDestination).at(
shellBarDestinations.indexOf(destination),
),
);
expect(target.width, greaterThanOrEqualTo(44), reason: label);
expect(target.height, greaterThanOrEqualTo(44), reason: label);
}
expect(
bounds.height,
greaterThan(FloatingDestinationBar.selectedButtonSize()),
);
expect(tester.getRect(pill()).right, 320 - 16);
});
}