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(
|
||||
|
||||
Reference in New Issue
Block a user