77a88d09d3
Show Back only when Settings is reached through a pushed route, and remove duplicate Settings controls where the shell already provides navigation. Update focused widget coverage and document the destination behavior.
152 lines
5.6 KiB
Dart
152 lines
5.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'destination.dart';
|
|
import 'list_detail_policy.dart';
|
|
|
|
/// The width of the destination rail on a wide window.
|
|
const double kNavigationRailWidth = 96;
|
|
|
|
/// The rail with its divider: what the rail takes from a wide window's width.
|
|
const double kNavigationRailSpace = kNavigationRailWidth + 1;
|
|
|
|
/// The narrowest window that shows the destination rail: the list-detail
|
|
/// minimum for the body beside it, plus the rail and its divider (the space the
|
|
/// shell takes from the window). Narrower windows keep the floating destination
|
|
/// bar, unchanged.
|
|
const double kNavigationRailMinWindowWidth =
|
|
kListDetailMinWidth + kNavigationRailSpace;
|
|
|
|
/// Whether the window at [context] shows the destination rail. Read from the
|
|
/// window's own [MediaQuery], so the shell and the floating windows layer
|
|
/// (which sits above the shell) agree.
|
|
bool showsNavigationRail(BuildContext context) =>
|
|
MediaQuery.sizeOf(context).width >= kNavigationRailMinWindowWidth;
|
|
|
|
/// Whether the window shows the floating tab bar alone: wide enough for a list
|
|
/// beside an open item, too narrow for the rail. That bar lists the tabs only,
|
|
/// so there Settings is reached from the Pipelines bar's gear.
|
|
bool showsFloatingTabBarOnly(BuildContext context) =>
|
|
showsListBesideDetail(context) && !showsNavigationRail(context);
|
|
|
|
/// The wide layout's left-edge navigation: a Material [NavigationRail] with
|
|
/// an icon and a label per tab, the selected tab marked by the rail's
|
|
/// indicator, and Settings pinned to its bottom.
|
|
///
|
|
/// [icon] builds each tab's icon (its running or unread badge included), so
|
|
/// the rail shows the same counts the floating bar did. [selected] is the
|
|
/// shell's destination: Settings (a page, not a tab) selects no tab but its
|
|
/// own item.
|
|
class ShellNavigationRail extends StatelessWidget {
|
|
const ShellNavigationRail({
|
|
super.key,
|
|
required this.selected,
|
|
required this.icon,
|
|
required this.onSelected,
|
|
this.padding = EdgeInsets.zero,
|
|
});
|
|
|
|
final AppDestination selected;
|
|
final Widget Function(AppDestination destination) icon;
|
|
final ValueChanged<AppDestination> onSelected;
|
|
|
|
/// The system insets the rail keeps clear of: the status bar above and the
|
|
/// navigation bar below.
|
|
final EdgeInsets padding;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final index = shellTabDestinations.indexOf(selected);
|
|
return Padding(
|
|
padding: padding,
|
|
child: SizedBox(
|
|
width: kNavigationRailWidth,
|
|
child: NavigationRail(
|
|
key: const ValueKey('shell.navigation-rail'),
|
|
minWidth: kNavigationRailWidth,
|
|
labelType: NavigationRailLabelType.all,
|
|
selectedIndex: index < 0 ? null : index,
|
|
onDestinationSelected: (value) =>
|
|
onSelected(shellTabDestinations[value]),
|
|
destinations: [
|
|
for (final destination in shellTabDestinations)
|
|
NavigationRailDestination(
|
|
icon: KeyedSubtree(
|
|
key: ValueKey('shell.destination.${destination.name}'),
|
|
// The bar it replaces named each tab in a tooltip too.
|
|
child: Tooltip(
|
|
message: destinationDetails(destination).label,
|
|
child: icon(destination),
|
|
),
|
|
),
|
|
label: Text(destinationDetails(destination).label),
|
|
),
|
|
],
|
|
trailingAtBottom: true,
|
|
trailing: _SettingsRailItem(
|
|
selected: selected == AppDestination.settings,
|
|
onTap: () => onSelected(AppDestination.settings),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Settings at the rail's foot, drawn as a [NavigationRailDestination] is: an
|
|
/// icon on a stadium indicator with its label under it, and the same colours.
|
|
/// It is not a [NavigationRailDestination] itself because the rail's
|
|
/// destination list is the tabs, and `trailing` is what the rail pins.
|
|
class _SettingsRailItem extends StatelessWidget {
|
|
const _SettingsRailItem({required this.selected, required this.onTap});
|
|
|
|
final bool selected;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final scheme = Theme.of(context).colorScheme;
|
|
final item = destinationDetails(AppDestination.settings);
|
|
final foreground = selected
|
|
? scheme.onSecondaryContainer
|
|
: scheme.onSurfaceVariant;
|
|
final textStyle = Theme.of(context).textTheme.labelMedium?.copyWith(
|
|
color: foreground,
|
|
fontWeight: selected ? FontWeight.w600 : FontWeight.w500,
|
|
);
|
|
return Semantics(
|
|
button: true,
|
|
selected: selected,
|
|
label: item.label,
|
|
child: ExcludeSemantics(
|
|
child: InkWell(
|
|
key: const ValueKey('shell.destination.settings'),
|
|
onTap: onTap,
|
|
child: SizedBox(
|
|
width: kNavigationRailWidth,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
width: 56,
|
|
height: 32,
|
|
alignment: Alignment.center,
|
|
decoration: ShapeDecoration(
|
|
shape: const StadiumBorder(),
|
|
color: selected ? scheme.secondaryContainer : null,
|
|
),
|
|
child: Icon(item.icon, color: foreground),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(item.label, style: textStyle),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|