feat(app): mirror the attention count on the Runs tab

This commit is contained in:
2026-10-22 18:40:55 +01:00
parent 1bcc26a4fd
commit eb80092860
9 changed files with 454 additions and 15 deletions
+38 -6
View File
@@ -1,6 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'attention_badge.dart';
import 'destination.dart';
class AdaptiveShell extends StatefulWidget {
@@ -11,6 +12,7 @@ class AdaptiveShell extends StatefulWidget {
this.destination,
this.onDestinationSelected,
this.onSearch,
this.attentionCount = 0,
});
final Map<AppDestination, WidgetBuilder> destinationBodies;
@@ -25,6 +27,10 @@ class AdaptiveShell extends StatefulWidget {
/// shell tests and compositions without routing keep their tab set only.
final VoidCallback? onSearch;
/// Runs needing the operator today, mirrored on the Runs tab in every mount
/// so it stays visible from any destination. Zero shows no badge.
final int attentionCount;
@override
State<AdaptiveShell> createState() => _AdaptiveShellState();
}
@@ -65,6 +71,17 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
List<T> _items<T>(T Function(AppDestination) build) =>
AppDestination.values.map(build).toList();
/// The destination's icon; only Runs carries the attention count.
Widget _icon(AppDestination destination, IconData data) {
final icon = Icon(data);
if (destination != AppDestination.runs) return icon;
return AttentionDestinationIcon(
count: widget.attentionCount,
cupertino: widget.cupertino,
child: icon,
);
}
@override
Widget build(BuildContext context) {
final index = AppDestination.values.indexOf(_selected);
@@ -108,6 +125,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
_CupertinoSidebar(
selected: _selected,
onSelected: _select,
attentionCount: widget.attentionCount,
),
Expanded(child: _destinationStack(contents, index)),
],
@@ -117,11 +135,12 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
Expanded(child: _destinationStack(contents, index)),
CupertinoTabBar(
currentIndex: index,
onTap: (value) => _select(AppDestination.values[value]),
onTap: (value) =>
_select(AppDestination.values[value]),
items: _items((destination) {
final item = destinationDetails(destination);
return BottomNavigationBarItem(
icon: Icon(item.cupertinoIcon),
icon: _icon(destination, item.cupertinoIcon),
label: item.label,
);
}),
@@ -155,7 +174,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
destinations: _items((destination) {
final item = destinationDetails(destination);
return NavigationRailDestination(
icon: Icon(item.icon),
icon: _icon(destination, item.icon),
label: Text(item.label),
);
}),
@@ -172,7 +191,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
destinations: _items((destination) {
final item = destinationDetails(destination);
return NavigationDestination(
icon: Icon(item.icon),
icon: _icon(destination, item.icon),
label: item.label,
);
}),
@@ -189,10 +208,15 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
/// The wide-window Cupertino destination list: the web's 200px rail with the
/// host's own grouped list controls.
class _CupertinoSidebar extends StatelessWidget {
const _CupertinoSidebar({required this.selected, required this.onSelected});
const _CupertinoSidebar({
required this.selected,
required this.onSelected,
this.attentionCount = 0,
});
final AppDestination selected;
final ValueChanged<AppDestination> onSelected;
final int attentionCount;
@override
Widget build(BuildContext context) {
@@ -215,7 +239,15 @@ class _CupertinoSidebar extends StatelessWidget {
for (final destination in AppDestination.values)
CupertinoListTile(
key: ValueKey('shell.destination.${destination.name}'),
leading: Icon(destinationDetails(destination).cupertinoIcon),
leading: destination == AppDestination.runs
? AttentionDestinationIcon(
count: attentionCount,
cupertino: true,
child: Icon(
destinationDetails(destination).cupertinoIcon,
),
)
: Icon(destinationDetails(destination).cupertinoIcon),
title: Text(destinationDetails(destination).label),
trailing: destination == selected
? Icon(
+82
View File
@@ -0,0 +1,82 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../features/attention/domain/attention_models.dart';
/// Mirrors the Runs-heading bell count onto the Runs destination icon.
///
/// The bell itself lives in the Runs heading, so without this the count would
/// be visible only on that destination; the web mirrors it on the rail and
/// dock tab. Material hosts use the framework [Badge]; Cupertino has no badge
/// control, so its tab bar and sidebar get the host's red count overlay. Zero
/// draws the bare icon, and a count labels the item exactly like the bell:
/// `Notifications, {n} needing attention`.
class AttentionDestinationIcon extends StatelessWidget {
const AttentionDestinationIcon({
super.key,
required this.count,
required this.cupertino,
required this.child,
});
final int count;
final bool cupertino;
final Widget child;
@override
Widget build(BuildContext context) {
final visible = count > 0;
final Widget icon = cupertino
? _CupertinoCountOverlay(count: count, visible: visible, child: child)
: Badge(label: Text('$count'), isLabelVisible: visible, child: child);
if (!visible) return icon;
// The number alone would read as a stray "3"; the item carries the bell's
// full label instead.
return Semantics(
label: attentionBadgeLabel(count),
child: ExcludeSemantics(child: icon),
);
}
}
/// The iOS tab-badge idiom: a red stadium with the count over the icon's
/// trailing corner. Content-driven size; only the overlap offset is fixed.
class _CupertinoCountOverlay extends StatelessWidget {
const _CupertinoCountOverlay({
required this.count,
required this.visible,
required this.child,
});
final int count;
final bool visible;
final Widget child;
@override
Widget build(BuildContext context) {
if (!visible) return child;
final style = CupertinoTheme.of(
context,
).textTheme.tabLabelTextStyle.copyWith(color: CupertinoColors.white);
return Stack(
clipBehavior: Clip.none,
children: [
child,
PositionedDirectional(
top: -6,
end: -10,
child: DecoratedBox(
decoration: ShapeDecoration(
color: CupertinoColors.systemRed.resolveFrom(context),
shape: const StadiumBorder(),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
child: Text('$count', style: style),
),
),
),
],
);
}
}