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
+18 -12
View File
@@ -8,6 +8,7 @@ import 'attention_badge.dart';
import 'destination.dart';
import 'list_detail.dart';
import 'navigation_rail.dart';
import 'shell_navigation_bar.dart';
import 'shell_rail_scope.dart';
import 'list_pane_widths.dart';
import 'shell_bar.dart';
@@ -149,7 +150,6 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
// only after the outgoing page has finished its native animation.
// Settings is shown as a page of the Pipelines tab: the tab bar keeps
// Pipelines selected and the bar offers Back to it.
final index = shellTabDestinations.indexOf(shellTabFor(_selected));
final page = !shellTabDestinations.contains(_selected);
final details = destinationDetails(_selected);
final contents = AppDestination.values.map((destination) {
@@ -175,23 +175,29 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
// Only the bar shows the registry's state, so a published bar or badge
// rebuilds its bar alone; the destinations and scaffold stay as built.
_bar.focus = _selected;
// One floating glass tab bar at every width: sized to its tabs at the
// right edge, near the thumb. Content keeps the whole width and scrolls
// behind it, learning the bar's height as its bottom media padding.
// A phone (narrower than the list-detail split) gets a full-width Material
// NavigationBar at the bottom, with Settings as its last destination. Wider
// windows without the rail keep the floating glass tab bar, which the list
// beside an open item needs (see below). Content keeps the whole width and
// scrolls behind the bar, learning its height as its bottom media padding.
// Neither scaffold's structure depends on the width, so resizing never
// remounts a destination.
//
// While the tab shows its list beside an open item the bar moves under
// the leading edge of the list pane, so the open item
// keeps its whole height: the list clears the bar and the item clears
// only the system inset (see ListDetailPanes). The bar keeps its place
// in the tree, so a split never replays its entrance.
// remounts a destination. Pushed detail routes cover the shell, and a
// bar-less spec (a chat workspace) hides the bar.
final phone = !showsListBesideDetail(context);
final bar = ListenableBuilder(
listenable: Listenable.merge([_bar.badges, _bar.bar, _paneWidths]),
builder: (context, _) {
if (_bar.specFor(_selected)?.hideNavigation ?? false) {
return const SizedBox.shrink();
}
if (phone) {
return ShellNavigationBar(
selected: _selected,
icon: (destination) =>
_icon(destination, destinationDetails(destination).icon),
onSelected: _select,
);
}
// On a wide window the bar stays under the list column even when no
// item is open (Search, a list alone), so it never jumps sides. A page
// (Settings) has no list column, so its bar stays at the right edge.
@@ -203,7 +209,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
alignment: AlignmentDirectional.bottomStart,
child: FloatingDestinationBar(
showLabels: true,
currentIndex: index,
currentIndex: shellTabDestinations.indexOf(shellTabFor(_selected)),
onTap: (value) => _select(shellTabDestinations[value]),
items: _destinationItems(),
alignment: split ? AlignmentDirectional.bottomStart : null,
+64
View File
@@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import 'destination.dart';
/// The destinations the phone's bottom bar offers, in order: the tabs, then
/// Settings. The rail pins Settings at its foot; a narrow window has no foot,
/// so Settings is the bar's last destination and is selected while it is open.
const List<AppDestination> shellBarDestinations = [
...shellTabDestinations,
AppDestination.settings,
];
/// The phone layout's bottom navigation: a full-width Material
/// [NavigationBar] with an icon and a label per destination, the current
/// destination marked by the bar's indicator.
///
/// [icon] builds each destination's icon (its running, needs-you or unread
/// badge included), the same builder the desktop rail uses, so both layouts
/// show the same counts. [selected] is the shell's destination. A re-tap of
/// the selected destination still calls [onSelected], which is how the shell's
/// destination-reselected hook fires.
///
/// The bar keeps the bottom system inset (gesture bar) clear and leaves while
/// the keyboard is open, so a field's text is never covered by the bar.
class ShellNavigationBar extends StatelessWidget {
const ShellNavigationBar({
super.key,
required this.selected,
required this.icon,
required this.onSelected,
});
final AppDestination selected;
final Widget Function(AppDestination destination) icon;
final ValueChanged<AppDestination> onSelected;
@override
Widget build(BuildContext context) {
// The keyboard takes the bottom of the window: the bar leaves with it.
if (MediaQuery.viewInsetsOf(context).bottom > 0) {
return const SizedBox.shrink();
}
return SafeArea(
top: false,
child: NavigationBar(
key: const ValueKey('shell.navigation-bar'),
selectedIndex: shellBarDestinations.indexOf(selected),
onDestinationSelected: (value) =>
onSelected(shellBarDestinations[value]),
destinations: [
for (final destination in shellBarDestinations)
NavigationDestination(
icon: KeyedSubtree(
key: ValueKey('shell.destination.${destination.name}'),
child: icon(destination),
),
label: destinationDetails(destination).label,
tooltip: destinationDetails(destination).label,
),
],
),
);
}
}