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:
@@ -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