Make Settings a first-class destination
Keep Settings location, selection, history, and persistence separate from Pipelines so /settings restores and navigates independently. Update focused navigation coverage and defer notification loading to avoid a mid-build Runs-tab update.
This commit is contained in:
@@ -26,7 +26,6 @@ class AdaptiveShell extends StatefulWidget {
|
||||
this.destination,
|
||||
this.onDestinationSelected,
|
||||
this.onDestinationReselected,
|
||||
this.onClosePage,
|
||||
this.onSearch,
|
||||
this.onOpenChat,
|
||||
this.attentionCount = 0,
|
||||
@@ -53,7 +52,6 @@ class AdaptiveShell extends StatefulWidget {
|
||||
/// already shown (a re-select). The host decides what it means; Chat reopens
|
||||
/// its active chats. Null keeps re-selects as plain selections.
|
||||
final ValueChanged<AppDestination>? onDestinationReselected;
|
||||
final VoidCallback? onClosePage;
|
||||
|
||||
/// Opens the transient Search page. Null hides the action, so the plain
|
||||
/// shell tests and compositions without routing keep their tab set only.
|
||||
@@ -166,8 +164,8 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
// Full-screen detail routes cover the shell themselves. Keep the root tabs
|
||||
// mounted/layout-ready underneath, so Back does not resize or reveal them
|
||||
// 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.
|
||||
// Settings is a destination of its own: a page with no tab of the bar
|
||||
// selected, and Back returns to the destination opened before it.
|
||||
final page = !shellTabDestinations.contains(_selected);
|
||||
final details = destinationDetails(_selected);
|
||||
final contents = AppDestination.values.map((destination) {
|
||||
@@ -227,7 +225,8 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
alignment: AlignmentDirectional.bottomStart,
|
||||
child: FloatingDestinationBar(
|
||||
showLabels: true,
|
||||
currentIndex: shellTabDestinations.indexOf(shellTabFor(_selected)),
|
||||
// A page (Settings) selects no tab: -1 highlights none.
|
||||
currentIndex: shellTabDestinations.indexOf(_selected),
|
||||
onTap: (value) => _tapDestination(shellTabDestinations[value]),
|
||||
items: _destinationItems(),
|
||||
alignment: split ? AlignmentDirectional.bottomStart : null,
|
||||
@@ -252,12 +251,13 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
// heights; panes beside a list read the real ones from here.
|
||||
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
|
||||
// app only from the first tab. Pages pushed over the shell (an item,
|
||||
// Search, a dialog) pop before this scope is asked. The scope is always
|
||||
// there, so opening the page never remounts the shell.
|
||||
// A page (Settings) closes to the destination opened before it on the
|
||||
// system Back too; at a tab's root Back returns to the destination opened
|
||||
// before it. Only with neither does Back reach the platform, so Android's
|
||||
// (predictive) Back closes the app only from the first destination. Pages
|
||||
// pushed over the shell (an item, Search, a dialog) pop before this scope
|
||||
// is asked. The scope is always there, so opening the page never remounts
|
||||
// the shell.
|
||||
Widget backable(Widget child) => PopScope(
|
||||
canPop: !page && _history.isEmpty,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
@@ -326,24 +326,21 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Leaves a page destination (Settings) for the tab it belongs to.
|
||||
/// Leaves a page destination (Settings) for the destination selected before
|
||||
/// it. With none recorded (a launch straight onto Settings) it opens Pipelines.
|
||||
void _closePage() {
|
||||
final close = widget.onClosePage;
|
||||
if (close != null) {
|
||||
close();
|
||||
} else {
|
||||
_select(shellTabFor(_selected));
|
||||
}
|
||||
_select(_history.takePrevious() ?? AppDestination.pipelines);
|
||||
}
|
||||
|
||||
/// The system Back the shell handles: it closes a page, or else returns to
|
||||
/// the previous tab unless the open item's own pane closes a page first.
|
||||
/// the previous destination unless the open item's own pane closes a page
|
||||
/// first.
|
||||
void _back({required bool page}) {
|
||||
if (page) {
|
||||
_closePage();
|
||||
return;
|
||||
}
|
||||
if (_nestedCanPop[shellTabFor(_selected)] ?? false) return;
|
||||
if (_nestedCanPop[_selected] ?? false) return;
|
||||
final previous = _history.takePrevious();
|
||||
if (previous != null) _select(previous);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
/// 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.
|
||||
/// The destinations the floating tab bar (or, on a wide window, the rail's
|
||||
/// tabs) offers, in order. Settings is a destination of its own, not a tab of
|
||||
/// Pipelines: it is selected alone, from the rail's foot on a wide window or as
|
||||
/// the phone bar's last item, and no tab in this list is highlighted while it
|
||||
/// is shown.
|
||||
const List<AppDestination> shellTabDestinations = [
|
||||
AppDestination.pipelines,
|
||||
AppDestination.runs,
|
||||
@@ -13,13 +14,6 @@ const List<AppDestination> shellTabDestinations = [
|
||||
AppDestination.search,
|
||||
];
|
||||
|
||||
/// The tab that owns [destination] in the tab bar: itself, or Pipelines for
|
||||
/// Settings (reached from the Pipelines bar).
|
||||
AppDestination shellTabFor(AppDestination destination) =>
|
||||
shellTabDestinations.contains(destination)
|
||||
? destination
|
||||
: AppDestination.pipelines;
|
||||
|
||||
/// The label and icons for [value].
|
||||
///
|
||||
({String label, IconData icon}) destinationDetails(AppDestination value) =>
|
||||
|
||||
@@ -1,40 +1,39 @@
|
||||
import 'destination.dart';
|
||||
|
||||
/// The tabs the operator left, most recent first, for the system Back.
|
||||
/// The destinations the operator left, most recent first, for the system Back.
|
||||
///
|
||||
/// Every tab change (a tap, a search result or notification opening
|
||||
/// another tab) goes through [record]: the tab being left moves to the top
|
||||
/// and the tab being opened leaves the stack, so each tab appears at most once
|
||||
/// and the current tab is never in it. A page that belongs to a tab
|
||||
/// (Settings, of Pipelines) is that tab here.
|
||||
/// Every destination change (a tap, a search result or notification opening
|
||||
/// another destination) goes through [record]: the destination being left moves
|
||||
/// to the top and the destination being opened leaves the stack, so each
|
||||
/// destination appears at most once and the current one is never in it.
|
||||
/// Settings is a destination of its own, so leaving it returns to whatever was
|
||||
/// selected before it.
|
||||
///
|
||||
/// [takePrevious] steps back: it removes the top tab and returns it, and the
|
||||
/// next [record] that opens that tab does not push the tab being left, so Back
|
||||
/// never builds a forward trail.
|
||||
/// [takePrevious] steps back: it removes the top destination and returns it, and
|
||||
/// the next [record] that opens that destination does not push the one being
|
||||
/// left, so Back never builds a forward trail.
|
||||
class TabHistory {
|
||||
final List<AppDestination> _tabs = [];
|
||||
AppDestination? _returningTo;
|
||||
|
||||
/// The left tabs, most recent first.
|
||||
/// The left destinations, most recent first.
|
||||
List<AppDestination> get tabs => List.unmodifiable(_tabs);
|
||||
|
||||
bool get isEmpty => _tabs.isEmpty;
|
||||
|
||||
/// Notes a change of the shown destination from [from] to [to].
|
||||
void record(AppDestination from, AppDestination to) {
|
||||
final left = shellTabFor(from);
|
||||
final opened = shellTabFor(to);
|
||||
if (left == opened) return;
|
||||
final returning = _returningTo == opened;
|
||||
if (from == to) return;
|
||||
final returning = _returningTo == to;
|
||||
_returningTo = null;
|
||||
_tabs.remove(opened);
|
||||
_tabs.remove(to);
|
||||
if (returning) return;
|
||||
_tabs
|
||||
..remove(left)
|
||||
..insert(0, left);
|
||||
..remove(from)
|
||||
..insert(0, from);
|
||||
}
|
||||
|
||||
/// The tab Back returns to, removed from the stack; null when empty.
|
||||
/// The destination Back returns to, removed from the stack; null when empty.
|
||||
AppDestination? takePrevious() {
|
||||
if (_tabs.isEmpty) return null;
|
||||
final previous = _tabs.removeAt(0);
|
||||
|
||||
Reference in New Issue
Block a user