Make Settings a top-level navigation destination
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.
This commit is contained in:
@@ -77,6 +77,11 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
late AppDestination _selected;
|
||||
final Set<AppDestination> _visited = {};
|
||||
final TabHistory _history = TabHistory();
|
||||
// The destination a shell control (rail, bar, floating bar) asked for and
|
||||
// that is not shown yet. Settings reached this way is a destination; any
|
||||
// other way in (a route, a deep link, the Pipelines gear) is a page to Back.
|
||||
AppDestination? _navigatingTo;
|
||||
bool _settingsPushed = false;
|
||||
// Whether a navigator inside each destination (an open item's pane) has a
|
||||
// page of its own for the system Back to close first.
|
||||
final Map<AppDestination, bool> _nestedCanPop = {};
|
||||
@@ -100,6 +105,9 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
super.initState();
|
||||
_bar.onNavigate = _select;
|
||||
_selected = widget.destination ?? AppDestination.pipelines;
|
||||
// A first load that opens Settings (a deep link, a restored page) was not
|
||||
// reached from a shell control, so its Back closes the page.
|
||||
_settingsPushed = _selected == AppDestination.settings;
|
||||
_visited.add(_selected);
|
||||
HardwareKeyboard.instance.addHandler(_handleDestinationKeyEvent);
|
||||
}
|
||||
@@ -109,12 +117,23 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
final destination = widget.destination;
|
||||
if (destination != null) {
|
||||
if (destination != _selected) _noteShown(destination);
|
||||
_history.record(_selected, destination);
|
||||
_selected = destination;
|
||||
_visited.add(destination);
|
||||
}
|
||||
}
|
||||
|
||||
/// Records that [destination] is becoming the shown one. Settings opened by
|
||||
/// a shell control is a destination (no Back); opened any other way it is a
|
||||
/// page that Back closes.
|
||||
void _noteShown(AppDestination destination) {
|
||||
if (destination == AppDestination.settings) {
|
||||
_settingsPushed = _navigatingTo != AppDestination.settings;
|
||||
}
|
||||
_navigatingTo = null;
|
||||
}
|
||||
|
||||
/// The entry every tab control calls when tapped: a destination shown
|
||||
/// already is re-selected (see [AdaptiveShell.onDestinationReselected]), any
|
||||
/// other is selected.
|
||||
@@ -124,6 +143,13 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
reselected(destination);
|
||||
return;
|
||||
}
|
||||
if (destination != _selected) {
|
||||
_navigatingTo = destination;
|
||||
// A selection the route never applies must not mark a later route.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted && _navigatingTo == destination) _navigatingTo = null;
|
||||
});
|
||||
}
|
||||
_select(destination);
|
||||
}
|
||||
|
||||
@@ -134,6 +160,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
if (destination != _selected) _noteShown(destination);
|
||||
_history.record(_selected, destination);
|
||||
_selected = destination;
|
||||
_visited.add(destination);
|
||||
@@ -440,7 +467,9 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
String label, {
|
||||
required bool page,
|
||||
}) {
|
||||
final onBack = spec?.onBack ?? (page ? _closePage : null);
|
||||
// Settings reached from a shell control has no Back: it is a destination.
|
||||
final onBack =
|
||||
spec?.onBack ?? (page && _settingsPushed ? _closePage : null);
|
||||
final published = spec?.actions ?? const <Widget>[];
|
||||
final onSearch = widget.onSearch;
|
||||
return SegmentedBar(
|
||||
|
||||
@@ -2,10 +2,11 @@ import 'package:flutter/material.dart';
|
||||
|
||||
enum AppDestination { pipelines, runs, chat, search, settings }
|
||||
|
||||
/// The destinations the shell's tab bar (or, on a wide window, its rail) offers,
|
||||
/// The tabs the shell's floating 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.
|
||||
/// `/settings`) and the rail and phone bar offer it too; it is a page of the
|
||||
/// Pipelines tab, not a tab. Only the floating bar's width leaves Settings to
|
||||
/// the Pipelines bar's gear.
|
||||
const List<AppDestination> shellTabDestinations = [
|
||||
AppDestination.pipelines,
|
||||
AppDestination.runs,
|
||||
|
||||
@@ -22,6 +22,12 @@ const double kNavigationRailMinWindowWidth =
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user