Add desktop navigation rail with Settings
Replace wide-layout floating destination controls with a full-height Material navigation rail, keeping badges and existing navigation behavior. Pin Settings to the rail and preserve the phone layout and pane/window clearance.
This commit is contained in:
@@ -7,6 +7,8 @@ import '../ui/adaptive/floating_destination_bar.dart';
|
||||
import 'attention_badge.dart';
|
||||
import 'destination.dart';
|
||||
import 'list_detail.dart';
|
||||
import 'navigation_rail.dart';
|
||||
import 'shell_rail_scope.dart';
|
||||
import 'list_pane_widths.dart';
|
||||
import 'shell_bar.dart';
|
||||
import 'shell_chat_shortcut.dart';
|
||||
@@ -223,7 +225,8 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
);
|
||||
// The scaffolds below swap the system insets for their bars'
|
||||
// heights; panes beside a list read the real ones from here.
|
||||
final system = MediaQuery.paddingOf(context);
|
||||
final media = MediaQuery.of(context);
|
||||
final system = media.padding;
|
||||
// A page (Settings) closes to Pipelines on the system Back too; at a
|
||||
// tab's root Back returns to the tab opened before it. Only with neither
|
||||
// does Back reach the platform, so Android's (predictive) Back closes the
|
||||
@@ -237,15 +240,60 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
},
|
||||
child: child,
|
||||
);
|
||||
// On a wide window the destinations sit in a rail at the left edge, and
|
||||
// the floating bar is not built; the scaffold gets the rest of the window.
|
||||
// The tree has the same shape at every width (an empty rail slot on a
|
||||
// phone), so resizing across the rail's threshold never remounts a
|
||||
// destination.
|
||||
final rail = showsNavigationRail(context);
|
||||
final scaffold = Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: topBar,
|
||||
body: _destinationStack(contents),
|
||||
extendBody: true,
|
||||
bottomNavigationBar: rail ? null : bar,
|
||||
);
|
||||
return backable(
|
||||
ShellSystemInsets(
|
||||
padding: system,
|
||||
child: Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: topBar,
|
||||
body: _destinationStack(contents),
|
||||
extendBody: true,
|
||||
bottomNavigationBar: bar,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// Badges (running runs, unread chats) rebuild the rail alone.
|
||||
ListenableBuilder(
|
||||
listenable: _bar.badges,
|
||||
builder: (context, _) => rail
|
||||
? ShellNavigationRail(
|
||||
selected: _selected,
|
||||
icon: (destination) => _icon(
|
||||
destination,
|
||||
destinationDetails(destination).icon,
|
||||
),
|
||||
onSelected: _select,
|
||||
padding: EdgeInsets.only(
|
||||
top: system.top,
|
||||
bottom: system.bottom,
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
// Three children at every width, so the body keeps its slot.
|
||||
rail
|
||||
? const VerticalDivider(width: 1, thickness: 1)
|
||||
: const SizedBox.shrink(),
|
||||
Expanded(
|
||||
// Beside the rail the panes lay out in the width the rail leaves,
|
||||
// which the window's width fixes here (not in a layout pass), so
|
||||
// the panes and their pages rebuild with the window.
|
||||
child: ShellRailScope(
|
||||
shown: rail,
|
||||
bodyWidth: rail
|
||||
? media.size.width - kNavigationRailSpace
|
||||
: null,
|
||||
child: scaffold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -2,9 +2,10 @@ import 'package:flutter/material.dart';
|
||||
|
||||
enum AppDestination { pipelines, runs, chat, search, settings }
|
||||
|
||||
/// The destinations the shell's tab bar offers, in order. Settings is a
|
||||
/// destination the shell can show (its route is `/settings`), but it opens
|
||||
/// as a page from the Pipelines bar's gear instead of being a tab.
|
||||
/// The destinations the shell's tab bar (or, on a wide window, its rail) offers,
|
||||
/// in order. Settings is a destination the shell can show (its route is
|
||||
/// `/settings`), but it opens as a page, from the rail's foot on a wide window
|
||||
/// or the Pipelines bar's gear on a phone, instead of being a tab.
|
||||
const List<AppDestination> shellTabDestinations = [
|
||||
AppDestination.pipelines,
|
||||
AppDestination.runs,
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'detail_pane_navigator.dart';
|
||||
import 'list_detail_policy.dart';
|
||||
import 'list_pane_divider.dart';
|
||||
import 'list_pane_widths.dart';
|
||||
import 'shell_rail_scope.dart';
|
||||
import 'shell_bar.dart';
|
||||
|
||||
export 'list_detail_policy.dart';
|
||||
@@ -64,7 +65,7 @@ class ListPaneWidth extends StatelessWidget {
|
||||
builder: (context, constraints) {
|
||||
final width = split
|
||||
? listDetailListWidth(
|
||||
MediaQuery.sizeOf(context).width,
|
||||
ShellRailScope.windowWidth(context),
|
||||
constraints.maxWidth,
|
||||
preferredWidth,
|
||||
)
|
||||
@@ -143,7 +144,7 @@ class _ListDetailPanesState extends State<ListDetailPanes> {
|
||||
listenable: widths,
|
||||
builder: (context, _) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final window = media.size.width;
|
||||
final window = ShellRailScope.windowWidth(context);
|
||||
final available = constraints.maxWidth;
|
||||
final preferred = widths.widthFor(key);
|
||||
final resizable =
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'shell_rail_scope.dart';
|
||||
|
||||
/// At least this wide, a destination keeps its list beside the open item
|
||||
/// (with the destination rail) instead of pushing the item as its own page.
|
||||
const double kListDetailMinWidth = 600;
|
||||
@@ -15,7 +17,7 @@ const double kListPaneMaxWidth = 440;
|
||||
|
||||
/// Whether the window at [context] shows list and detail side by side.
|
||||
bool showsListBesideDetail(BuildContext context) =>
|
||||
MediaQuery.sizeOf(context).width >= kListDetailMinWidth;
|
||||
ShellRailScope.windowWidth(context) >= kListDetailMinWidth;
|
||||
|
||||
/// The narrowest list pane a drag leaves.
|
||||
const double kListPaneMinWidth = 240;
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
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;
|
||||
|
||||
/// 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),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Marks the content beside the destination rail. A wide window's content
|
||||
/// lays out in the width left beside the rail, so list and detail panes read
|
||||
/// that width ([windowWidth]) instead of the window's. Outside the scope (a
|
||||
/// phone, a route pushed over the shell) the window's own width applies.
|
||||
class ShellRailScope extends InheritedWidget {
|
||||
const ShellRailScope({
|
||||
super.key,
|
||||
required this.shown,
|
||||
required this.bodyWidth,
|
||||
required super.child,
|
||||
});
|
||||
|
||||
/// Whether the rail is shown beside this content.
|
||||
final bool shown;
|
||||
|
||||
/// The width beside the rail; null when no rail is shown.
|
||||
final double? bodyWidth;
|
||||
|
||||
/// Whether the rail is shown beside [context]'s content.
|
||||
static bool isShown(BuildContext context) =>
|
||||
context.dependOnInheritedWidgetOfExactType<ShellRailScope>()?.shown ??
|
||||
false;
|
||||
|
||||
/// The width the panes of [context] lay out in: the body beside the rail,
|
||||
/// or else the window.
|
||||
static double windowWidth(BuildContext context) =>
|
||||
context.dependOnInheritedWidgetOfExactType<ShellRailScope>()?.bodyWidth ??
|
||||
MediaQuery.sizeOf(context).width;
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(ShellRailScope oldWidget) =>
|
||||
shown != oldWidget.shown || bodyWidth != oldWidget.bodyWidth;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../navigation_rail.dart';
|
||||
import 'window_focus.dart';
|
||||
import 'window_layer.dart';
|
||||
import 'window_manager.dart';
|
||||
@@ -18,7 +19,16 @@ import 'window_shortcuts.dart';
|
||||
///
|
||||
/// The host fills its parent and takes no input between windows.
|
||||
class WindowHost extends StatefulWidget {
|
||||
const WindowHost({super.key, required this.manager});
|
||||
const WindowHost({
|
||||
super.key,
|
||||
required this.manager,
|
||||
this.reservesRail = false,
|
||||
});
|
||||
|
||||
/// Whether the shell beside this host shows the destination rail on the
|
||||
/// window's left edge; the windows then keep to the right of it while the
|
||||
/// window is wide enough for the rail (see [showsNavigationRail]).
|
||||
final bool reservesRail;
|
||||
|
||||
final WindowManager manager;
|
||||
|
||||
@@ -119,24 +129,36 @@ class _WindowHostState extends State<WindowHost> {
|
||||
]),
|
||||
builder: (context, _) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final bounds = constraints.biggest;
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
for (final entry in windows)
|
||||
if (manager.kinds[entry.kind] case final kind?)
|
||||
WindowLayer(
|
||||
key: ValueKey(entry.id),
|
||||
manager: manager,
|
||||
kind: kind,
|
||||
entry: entry,
|
||||
visible:
|
||||
manager.isVisible(entry) &&
|
||||
bounds.width >= kind.minHostWidth,
|
||||
bounds: bounds,
|
||||
focus: _focus,
|
||||
),
|
||||
],
|
||||
// Beside the destination rail the windows keep to the page's
|
||||
// right, so they never sit under the rail.
|
||||
// The shell takes the rail and its divider (kNavigationRailSpace).
|
||||
final leading = widget.reservesRail && showsNavigationRail(context)
|
||||
? kNavigationRailSpace
|
||||
: 0.0;
|
||||
final bounds = Size(
|
||||
constraints.maxWidth - leading,
|
||||
constraints.maxHeight,
|
||||
);
|
||||
return Padding(
|
||||
padding: EdgeInsetsDirectional.only(start: leading),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
for (final entry in windows)
|
||||
if (manager.kinds[entry.kind] case final kind?)
|
||||
WindowLayer(
|
||||
key: ValueKey(entry.id),
|
||||
manager: manager,
|
||||
kind: kind,
|
||||
entry: entry,
|
||||
visible:
|
||||
manager.isVisible(entry) &&
|
||||
bounds.width >= kind.minHostWidth,
|
||||
bounds: bounds,
|
||||
focus: _focus,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user