feat(app): Runs and Chat tabs badge running runs and unread chats; unread chat rows carry a New badge

This commit is contained in:
2026-10-23 20:15:01 +01:00
parent 11ab9beb7b
commit d373f4c48e
7 changed files with 247 additions and 5 deletions
+73
View File
@@ -15,6 +15,18 @@ class ShellBarSpec {
/// The bar contents each tab's open screen has published.
class ShellBarRegistry extends ChangeNotifier {
final Map<AppDestination, (Object, ShellBarSpec)> _specs = {};
final Map<(AppDestination, ShellBadgeKind), int> _badges = {};
/// The count a tab's screen published for [kind], 0 when none.
int badge(AppDestination destination, ShellBadgeKind kind) =>
_badges[(destination, kind)] ?? 0;
void _setBadge(AppDestination destination, ShellBadgeKind kind, int count) {
if (_disposed || badge(destination, kind) == count) return;
_badges[(destination, kind)] = count;
notifyListeners();
}
bool _disposed = false;
@override
@@ -138,3 +150,64 @@ class _ShellBarState extends State<ShellBar> {
return widget.child;
}
}
/// What a tab badge counts.
enum ShellBadgeKind {
/// Runs still executing.
running,
/// Chats with messages not yet seen.
unread,
}
/// Publishes a count for this tab's badge while [child] is mounted.
class ShellBadge extends StatefulWidget {
const ShellBadge({
super.key,
required this.kind,
required this.count,
required this.child,
});
final ShellBadgeKind kind;
final int count;
final Widget child;
@override
State<ShellBadge> createState() => _ShellBadgeState();
}
class _ShellBadgeState extends State<ShellBadge> {
ShellBarScope? _scope;
@override
void didChangeDependencies() {
super.didChangeDependencies();
_scope = ShellBarScope.maybeOf(context);
}
@override
void dispose() {
final scope = _scope;
final kind = widget.kind;
if (scope != null) {
WidgetsBinding.instance.addPostFrameCallback(
(_) => scope.registry._setBadge(scope.destination, kind, 0),
);
}
super.dispose();
}
@override
Widget build(BuildContext context) {
final scope = _scope;
if (scope != null) {
final count = widget.count;
final kind = widget.kind;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) scope.registry._setBadge(scope.destination, kind, count);
});
}
return widget.child;
}
}