Share one minute clock across time labels and narrow shell and runs rebuilds
Relative-time labels follow one wall-minute RelativeTimeClock instead of a timer per row, skip ticks while their tab is offstage and rebuild only when their text changes. The shell rebuilds its top bar only for the focused destination's published bar and its tab bar only for badge changes. Run events that repeat a row's state no longer notify, and the runs list filters and sorts once per build. Adds a rebuild/timer benchmark.
This commit is contained in:
@@ -140,78 +140,81 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
return ListenableBuilder(
|
||||
listenable: _bar,
|
||||
builder: (context, _) {
|
||||
final spec = _bar.specFor(_selected);
|
||||
// One floating glass tab bar at every width: full width on a phone,
|
||||
// sized to its tabs at the right edge on a wide window (the bar judges
|
||||
// that itself, live). Content keeps the whole width and scrolls behind
|
||||
// it, learning the bar's height as its bottom media padding. Neither
|
||||
// scaffold's structure depends on the width, so resizing never
|
||||
// remounts a destination.
|
||||
//
|
||||
// While the tab shows its list beside an open item the bar keeps
|
||||
// the same place, bottom right near the thumb: the item pane learns
|
||||
// the bar's height (see ListDetailPanes) and floats its own tabs or
|
||||
// composer above it, so the two never overlap.
|
||||
final split = _bar.split(_selected);
|
||||
final bar = FloatingDestinationBar(
|
||||
cupertino: widget.cupertino,
|
||||
currentIndex: index,
|
||||
onTap: (value) => _select(shellTabDestinations[value]),
|
||||
items: _destinationItems(),
|
||||
);
|
||||
// Destinations reach the top edge and scroll behind the floating top
|
||||
// bar too: each learns the bar's height as its top media padding and
|
||||
// pads its own lists by it (see withTopBarClearance).
|
||||
final topBar = _ListPaneBar(
|
||||
split: split,
|
||||
bar: _segmentedBar(spec, details.label, page: page),
|
||||
);
|
||||
// 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);
|
||||
// A page (Settings) closes to Pipelines on the system Back too. The
|
||||
// scope is always there, so opening the page never remounts the shell.
|
||||
Widget backable(Widget child) => PopScope(
|
||||
canPop: !page,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop) _closePage();
|
||||
},
|
||||
child: child,
|
||||
);
|
||||
if (widget.cupertino) {
|
||||
return backable(
|
||||
ShellSystemInsets(
|
||||
padding: system,
|
||||
child: CupertinoPageScaffold(
|
||||
navigationBar: topBar,
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: FloatingBarOverlay(
|
||||
bar: bar,
|
||||
child: _destinationStack(contents),
|
||||
),
|
||||
),
|
||||
// Only the bar shows the registry's state, so a published bar or badge
|
||||
// rebuilds its bar alone; the destinations and scaffold stay as built.
|
||||
_bar.focus = _selected;
|
||||
// One floating glass tab bar at every width: full width on a phone,
|
||||
// sized to its tabs at the right edge on a wide window (the bar judges
|
||||
// that itself, live). Content keeps the whole width and scrolls behind
|
||||
// it, learning the bar's height as its bottom media padding. Neither
|
||||
// scaffold's structure depends on the width, so resizing never
|
||||
// remounts a destination.
|
||||
//
|
||||
// While the tab shows its list beside an open item the bar keeps
|
||||
// the same place, bottom right near the thumb: the item pane learns
|
||||
// the bar's height (see ListDetailPanes) and floats its own tabs or
|
||||
// composer above it, so the two never overlap.
|
||||
final bar = ListenableBuilder(
|
||||
listenable: _bar.badges,
|
||||
builder: (context, _) => FloatingDestinationBar(
|
||||
cupertino: widget.cupertino,
|
||||
currentIndex: index,
|
||||
onTap: (value) => _select(shellTabDestinations[value]),
|
||||
items: _destinationItems(),
|
||||
),
|
||||
);
|
||||
// Destinations reach the top edge and scroll behind the floating top
|
||||
// bar too: each learns the bar's height as its top media padding and
|
||||
// pads its own lists by it (see withTopBarClearance).
|
||||
SegmentedBar currentBar() =>
|
||||
_segmentedBar(_bar.specFor(_selected), details.label, page: page);
|
||||
final topBar = _ListPaneBar(
|
||||
listenable: _bar.bar,
|
||||
initial: currentBar(),
|
||||
split: () => _bar.split(_selected),
|
||||
bar: currentBar,
|
||||
);
|
||||
// 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);
|
||||
// A page (Settings) closes to Pipelines on the system Back too. The
|
||||
// scope is always there, so opening the page never remounts the shell.
|
||||
Widget backable(Widget child) => PopScope(
|
||||
canPop: !page,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop) _closePage();
|
||||
},
|
||||
child: child,
|
||||
);
|
||||
if (widget.cupertino) {
|
||||
return backable(
|
||||
ShellSystemInsets(
|
||||
padding: system,
|
||||
child: CupertinoPageScaffold(
|
||||
navigationBar: topBar,
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: FloatingBarOverlay(
|
||||
bar: bar,
|
||||
child: _destinationStack(contents),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return backable(
|
||||
ShellSystemInsets(
|
||||
padding: system,
|
||||
child: Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: topBar,
|
||||
body: _destinationStack(contents),
|
||||
extendBody: true,
|
||||
bottomNavigationBar: bar,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
return backable(
|
||||
ShellSystemInsets(
|
||||
padding: system,
|
||||
child: Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: topBar,
|
||||
body: _destinationStack(contents),
|
||||
extendBody: true,
|
||||
bottomNavigationBar: bar,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -328,24 +331,38 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
/// beside an open item ([ShellPaneSplit]); the item's own bar takes the rest
|
||||
/// of the same row. The bar keeps its place in the scaffold either way, so a
|
||||
/// split never remounts it.
|
||||
///
|
||||
/// It rebuilds itself when [listenable] (the focused destination's published
|
||||
/// bar) changes; [initial] supplies the size and obstruction, which do not
|
||||
/// depend on the published contents.
|
||||
class _ListPaneBar extends StatelessWidget
|
||||
implements ObstructingPreferredSizeWidget {
|
||||
const _ListPaneBar({required this.split, required this.bar});
|
||||
const _ListPaneBar({
|
||||
required this.listenable,
|
||||
required this.initial,
|
||||
required this.split,
|
||||
required this.bar,
|
||||
});
|
||||
|
||||
final bool split;
|
||||
final SegmentedBar bar;
|
||||
final Listenable listenable;
|
||||
final SegmentedBar initial;
|
||||
final bool Function() split;
|
||||
final SegmentedBar Function() bar;
|
||||
|
||||
@override
|
||||
Size get preferredSize => bar.preferredSize;
|
||||
Size get preferredSize => initial.preferredSize;
|
||||
|
||||
@override
|
||||
bool shouldFullyObstruct(BuildContext context) =>
|
||||
bar.shouldFullyObstruct(context);
|
||||
initial.shouldFullyObstruct(context);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ListPaneWidth(
|
||||
split: split,
|
||||
alignment: AlignmentDirectional.topStart,
|
||||
child: bar,
|
||||
Widget build(BuildContext context) => ListenableBuilder(
|
||||
listenable: listenable,
|
||||
builder: (context, _) => ListPaneWidth(
|
||||
split: split(),
|
||||
alignment: AlignmentDirectional.topStart,
|
||||
child: bar(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -53,9 +53,37 @@ class ShellBarSpec {
|
||||
}
|
||||
|
||||
/// The bar contents each tab's open screen has published.
|
||||
///
|
||||
/// It notifies its own listeners of every visible change. A host that shows
|
||||
/// one destination's bar at a time sets [focus] and may listen to [bar] and
|
||||
/// [badges] separately: a hidden tab republishing its bar (a list rebuilding
|
||||
/// on a run event) then rebuilds nothing, and a badge change rebuilds only
|
||||
/// the tab bar.
|
||||
class ShellBarRegistry extends ChangeNotifier {
|
||||
final Map<AppDestination, (Object, ShellBarSpec)> _specs = {};
|
||||
final Map<(AppDestination, ShellBadgeKind), int> _badges = {};
|
||||
final _Notifier _bar = _Notifier();
|
||||
final _Notifier _badgeNotifier = _Notifier();
|
||||
|
||||
/// The destination whose bar is on screen; null treats every destination
|
||||
/// as shown. Bar changes of other destinations are kept without notifying:
|
||||
/// the host rebuilds when it changes the focus.
|
||||
AppDestination? focus;
|
||||
|
||||
/// Notifies when the focused destination's bar spec or split changes.
|
||||
Listenable get bar => _bar;
|
||||
|
||||
/// Notifies when any tab badge count changes.
|
||||
Listenable get badges => _badgeNotifier;
|
||||
|
||||
bool _shown(AppDestination destination) =>
|
||||
focus == null || focus == destination;
|
||||
|
||||
void _barChanged(AppDestination destination) {
|
||||
if (!_shown(destination)) return;
|
||||
_bar.notify();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
final Map<AppDestination, int> _splits = {};
|
||||
|
||||
@@ -68,7 +96,7 @@ class ShellBarRegistry extends ChangeNotifier {
|
||||
if (_disposed) return;
|
||||
final before = split(destination);
|
||||
_splits[destination] = (_splits[destination] ?? 0) + (value ? 1 : -1);
|
||||
if (split(destination) != before) notifyListeners();
|
||||
if (split(destination) != before) _barChanged(destination);
|
||||
}
|
||||
|
||||
/// The count a tab's screen published for [kind], 0 when none.
|
||||
@@ -78,6 +106,7 @@ class ShellBarRegistry extends ChangeNotifier {
|
||||
void _setBadge(AppDestination destination, ShellBadgeKind kind, int count) {
|
||||
if (_disposed || badge(destination, kind) == count) return;
|
||||
_badges[(destination, kind)] = count;
|
||||
_badgeNotifier.notify();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -86,6 +115,8 @@ class ShellBarRegistry extends ChangeNotifier {
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
_bar.dispose();
|
||||
_badgeNotifier.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -99,17 +130,21 @@ class ShellBarRegistry extends ChangeNotifier {
|
||||
// A screen's update can land after the shell itself has gone.
|
||||
if (_disposed) return;
|
||||
_specs[destination] = (owner, spec);
|
||||
notifyListeners();
|
||||
_barChanged(destination);
|
||||
}
|
||||
|
||||
void _clear(AppDestination destination, Object owner) {
|
||||
if (_disposed) return;
|
||||
if (_specs[destination]?.$1 != owner) return;
|
||||
_specs.remove(destination);
|
||||
notifyListeners();
|
||||
_barChanged(destination);
|
||||
}
|
||||
}
|
||||
|
||||
class _Notifier extends ChangeNotifier {
|
||||
void notify() => notifyListeners();
|
||||
}
|
||||
|
||||
/// Places one tab's content under the shell's bar registry.
|
||||
class ShellBarScope extends InheritedWidget {
|
||||
const ShellBarScope({
|
||||
|
||||
Reference in New Issue
Block a user