feat(app): mirror the attention count on the Runs tab
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/scheduler.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
@@ -10,6 +11,8 @@ import '../shell/adaptive_shell.dart';
|
|||||||
import '../shell/destination.dart';
|
import '../shell/destination.dart';
|
||||||
import '../features/attention/notify/notification_controller.dart';
|
import '../features/attention/notify/notification_controller.dart';
|
||||||
import '../features/attention/notify/notification_store.dart';
|
import '../features/attention/notify/notification_store.dart';
|
||||||
|
import '../features/attention/runtime/attention_controller.dart';
|
||||||
|
import '../features/attention/runtime/attention_store.dart';
|
||||||
import '../features/runs/ui/run_search_selection.dart';
|
import '../features/runs/ui/run_search_selection.dart';
|
||||||
import '../features/search/domain/search_target.dart';
|
import '../features/search/domain/search_target.dart';
|
||||||
import '../features/settings/settings_screen.dart';
|
import '../features/settings/settings_screen.dart';
|
||||||
@@ -89,6 +92,20 @@ class _PipelinesAppState extends State<PipelinesApp>
|
|||||||
store: const SharedPreferencesNotificationStore(),
|
store: const SharedPreferencesNotificationStore(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// One attention surface for the app: the Runs heading's bell draws from it
|
||||||
|
/// and the shell mirrors its count on the Runs tab, so the badge is visible
|
||||||
|
/// from every destination. The Runs list seeds the rows when it loads; pushed
|
||||||
|
/// `run_event` frames are folded here so the count moves while another
|
||||||
|
/// destination is shown, and a replaced socket drops the status baseline.
|
||||||
|
late final AttentionController _attention = AttentionController(
|
||||||
|
store: const SharedPreferencesAttentionStore(),
|
||||||
|
);
|
||||||
|
StreamSubscription<JsonMap>? _attentionFrames;
|
||||||
|
int _attentionEpoch = 0;
|
||||||
|
|
||||||
|
/// The count the shell's Runs tab shows; only a changed count rebuilds it.
|
||||||
|
final ValueNotifier<int> _attentionCount = ValueNotifier<int>(0);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -115,6 +132,12 @@ class _PipelinesAppState extends State<PipelinesApp>
|
|||||||
_cupertino = widget.cupertino ?? _platformIsCupertino;
|
_cupertino = widget.cupertino ?? _platformIsCupertino;
|
||||||
_notifications.onOpenRun = (id) => _delegate.goTo(AppRoute.run(id));
|
_notifications.onOpenRun = (id) => _delegate.goTo(AppRoute.run(id));
|
||||||
unawaited(_notifications.load());
|
unawaited(_notifications.load());
|
||||||
|
unawaited(_attention.load());
|
||||||
|
_attentionFrames = _session.gateway.frames
|
||||||
|
.where((frame) => frame['type'] == 'run_event')
|
||||||
|
.listen(_attention.observeFrame);
|
||||||
|
_session.addListener(_attentionSessionChanged);
|
||||||
|
_attention.addListener(_attentionChanged);
|
||||||
_delegate = AppRouterDelegate(
|
_delegate = AppRouterDelegate(
|
||||||
initial: initial,
|
initial: initial,
|
||||||
cupertino: _cupertino,
|
cupertino: _cupertino,
|
||||||
@@ -137,6 +160,11 @@ class _PipelinesAppState extends State<PipelinesApp>
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
WidgetsBinding.instance.removeObserver(this);
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
|
_session.removeListener(_attentionSessionChanged);
|
||||||
|
unawaited(_attentionFrames?.cancel());
|
||||||
|
_attention.removeListener(_attentionChanged);
|
||||||
|
_attention.dispose();
|
||||||
|
_attentionCount.dispose();
|
||||||
_notifications.dispose();
|
_notifications.dispose();
|
||||||
_delegate.removeListener(_routeChanged);
|
_delegate.removeListener(_routeChanged);
|
||||||
_delegate.dispose();
|
_delegate.dispose();
|
||||||
@@ -161,6 +189,33 @@ class _PipelinesAppState extends State<PipelinesApp>
|
|||||||
unawaited(_session.retry());
|
unawaited(_session.retry());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A replaced socket drops the attention status baseline so the gap cannot
|
||||||
|
/// replay a transition; the Runs list's next read reseeds the rows.
|
||||||
|
void _attentionSessionChanged() {
|
||||||
|
final epoch = _session.connectionEpoch;
|
||||||
|
if (epoch == _attentionEpoch) return;
|
||||||
|
_attentionEpoch = epoch;
|
||||||
|
_attention.resetForReconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Mirrors the controller's entry count for the shell. The Runs list seeds
|
||||||
|
/// the rows from inside its own build, and the shell sits above that layout
|
||||||
|
/// scope, so a count that changes mid-build lands after the frame; a pushed
|
||||||
|
/// frame arrives outside any build and applies at once.
|
||||||
|
void _attentionChanged() {
|
||||||
|
if (!mounted) return;
|
||||||
|
final count = _attention.entries.length;
|
||||||
|
if (count == _attentionCount.value) return;
|
||||||
|
if (SchedulerBinding.instance.schedulerPhase ==
|
||||||
|
SchedulerPhase.persistentCallbacks) {
|
||||||
|
SchedulerBinding.instance.addPostFrameCallback(
|
||||||
|
(_) => _attentionChanged(),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_attentionCount.value = count;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) =>
|
Widget build(BuildContext context) =>
|
||||||
MyApp.router(cupertino: _cupertino, routerConfig: _config);
|
MyApp.router(cupertino: _cupertino, routerConfig: _config);
|
||||||
@@ -277,7 +332,16 @@ class _PipelinesAppState extends State<PipelinesApp>
|
|||||||
_delegate.goTo(AppRoute.run(id));
|
_delegate.goTo(AppRoute.run(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildShell(BuildContext context, AppRoute route) => AdaptiveShell(
|
/// The shell rebuilds its Runs tab badge from the attention count alone; the
|
||||||
|
/// destination bodies keep their state through it.
|
||||||
|
Widget _buildShell(BuildContext context, AppRoute route) =>
|
||||||
|
ValueListenableBuilder<int>(
|
||||||
|
valueListenable: _attentionCount,
|
||||||
|
builder: (context, count, _) => _shellFor(route, count),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _shellFor(AppRoute route, int attentionCount) => AdaptiveShell(
|
||||||
|
attentionCount: attentionCount,
|
||||||
cupertino: _cupertino,
|
cupertino: _cupertino,
|
||||||
destination: _destinationOf(route.kind),
|
destination: _destinationOf(route.kind),
|
||||||
onDestinationSelected: (destination) =>
|
onDestinationSelected: (destination) =>
|
||||||
@@ -307,6 +371,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
|||||||
initialDecide: route.decide,
|
initialDecide: route.decide,
|
||||||
listRefreshToken: _runsRefresh,
|
listRefreshToken: _runsRefresh,
|
||||||
notifications: _notifications,
|
notifications: _notifications,
|
||||||
|
attention: _attention,
|
||||||
onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)),
|
onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)),
|
||||||
onBack: () => _delegate.goTo(AppRoute.runs),
|
onBack: () => _delegate.goTo(AppRoute.runs),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../features/attention/notify/notification_controller.dart';
|
import '../features/attention/notify/notification_controller.dart';
|
||||||
|
import '../features/attention/runtime/attention_controller.dart';
|
||||||
import '../features/runs/screen.dart';
|
import '../features/runs/screen.dart';
|
||||||
import '../ui/adaptive/host.dart';
|
import '../ui/adaptive/host.dart';
|
||||||
import 'app_session.dart';
|
import 'app_session.dart';
|
||||||
@@ -26,6 +27,7 @@ class RunsDestination extends StatelessWidget {
|
|||||||
this.onBack,
|
this.onBack,
|
||||||
this.listRefreshToken = 0,
|
this.listRefreshToken = 0,
|
||||||
this.notifications,
|
this.notifications,
|
||||||
|
this.attention,
|
||||||
});
|
});
|
||||||
|
|
||||||
final AppSession session;
|
final AppSession session;
|
||||||
@@ -52,6 +54,9 @@ class RunsDestination extends StatelessWidget {
|
|||||||
/// The app-level notification capability shared with Settings.
|
/// The app-level notification capability shared with Settings.
|
||||||
final NotificationController? notifications;
|
final NotificationController? notifications;
|
||||||
|
|
||||||
|
/// The app-level attention controller the shell's Runs tab badge reads.
|
||||||
|
final AttentionController? attention;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => AnimatedBuilder(
|
Widget build(BuildContext context) => AnimatedBuilder(
|
||||||
animation: session,
|
animation: session,
|
||||||
@@ -93,6 +98,7 @@ class RunsDestination extends StatelessWidget {
|
|||||||
syncToken: session.connectionEpoch,
|
syncToken: session.connectionEpoch,
|
||||||
listRefreshToken: listRefreshToken,
|
listRefreshToken: listRefreshToken,
|
||||||
notifications: notifications,
|
notifications: notifications,
|
||||||
|
attention: attention,
|
||||||
onRunSelected: onRunSelected,
|
onRunSelected: onRunSelected,
|
||||||
onBack: onBack,
|
onBack: onBack,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class NeedsYouRunsHeading extends StatefulWidget {
|
|||||||
this.now,
|
this.now,
|
||||||
this.cupertino,
|
this.cupertino,
|
||||||
this.notifications,
|
this.notifications,
|
||||||
|
this.attention,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// The run summaries the Runs destination already holds.
|
/// The run summaries the Runs destination already holds.
|
||||||
@@ -55,23 +56,36 @@ class NeedsYouRunsHeading extends StatefulWidget {
|
|||||||
/// the bell, so no store or platform bridge is touched there.
|
/// the bell, so no store or platform bridge is touched there.
|
||||||
final NotificationController? notifications;
|
final NotificationController? notifications;
|
||||||
|
|
||||||
|
/// The app's shared attention controller, so the shell can mirror the same
|
||||||
|
/// count on the Runs tab. The heading seeds it with [rows]; its owner folds
|
||||||
|
/// [frames] and resets it on reconnect. Absent, the heading owns a private
|
||||||
|
/// controller fed from [frames], which fixtures and the list tests rely on.
|
||||||
|
final AttentionController? attention;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<NeedsYouRunsHeading> createState() => _NeedsYouRunsHeadingState();
|
State<NeedsYouRunsHeading> createState() => _NeedsYouRunsHeadingState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
|
class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
|
||||||
late final AttentionController _attention = AttentionController(
|
late final AttentionController _attention =
|
||||||
store: widget.store,
|
widget.attention ??
|
||||||
now: widget.now,
|
AttentionController(store: widget.store, now: widget.now);
|
||||||
);
|
|
||||||
StreamSubscription<JsonMap>? _frames;
|
StreamSubscription<JsonMap>? _frames;
|
||||||
|
|
||||||
|
bool get _ownsController => widget.attention == null;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_attention.seedRows(widget.rows);
|
_attention.seedRows(widget.rows);
|
||||||
unawaited(_attention.load());
|
if (_ownsController) {
|
||||||
_listen();
|
unawaited(_attention.load());
|
||||||
|
_listen();
|
||||||
|
} else {
|
||||||
|
// The owner folds frames; publishing after every change it makes is the
|
||||||
|
// same idempotent call the private path makes after each frame.
|
||||||
|
_attention.addListener(_publish);
|
||||||
|
}
|
||||||
final notifications = widget.notifications;
|
final notifications = widget.notifications;
|
||||||
if (notifications != null) {
|
if (notifications != null) {
|
||||||
notifications.onOpenRun = _openRunById;
|
notifications.onOpenRun = _openRunById;
|
||||||
@@ -115,7 +129,7 @@ class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
|
|||||||
@override
|
@override
|
||||||
void didUpdateWidget(covariant NeedsYouRunsHeading oldWidget) {
|
void didUpdateWidget(covariant NeedsYouRunsHeading oldWidget) {
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
if (!identical(oldWidget.frames, widget.frames)) {
|
if (_ownsController && !identical(oldWidget.frames, widget.frames)) {
|
||||||
unawaited(_frames?.cancel());
|
unawaited(_frames?.cancel());
|
||||||
_frames = null;
|
_frames = null;
|
||||||
_listen();
|
_listen();
|
||||||
@@ -135,7 +149,11 @@ class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
unawaited(_frames?.cancel());
|
unawaited(_frames?.cancel());
|
||||||
_attention.dispose();
|
if (_ownsController) {
|
||||||
|
_attention.dispose();
|
||||||
|
} else {
|
||||||
|
_attention.removeListener(_publish);
|
||||||
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'package:flutter/widgets.dart';
|
|||||||
import '../../core/api_gateway.dart';
|
import '../../core/api_gateway.dart';
|
||||||
import '../../ui/adaptive/host.dart';
|
import '../../ui/adaptive/host.dart';
|
||||||
import '../attention/notify/notification_controller.dart';
|
import '../attention/notify/notification_controller.dart';
|
||||||
|
import '../attention/runtime/attention_controller.dart';
|
||||||
import '../attention/runtime/attention_store.dart';
|
import '../attention/runtime/attention_store.dart';
|
||||||
import 'actions/decision_action.dart';
|
import 'actions/decision_action.dart';
|
||||||
import 'data/runs_repository.dart';
|
import 'data/runs_repository.dart';
|
||||||
@@ -34,6 +35,7 @@ class RunsScreen extends StatefulWidget {
|
|||||||
this.attentionStore = const SharedPreferencesAttentionStore(),
|
this.attentionStore = const SharedPreferencesAttentionStore(),
|
||||||
this.attentionNow,
|
this.attentionNow,
|
||||||
this.notifications,
|
this.notifications,
|
||||||
|
this.attention,
|
||||||
});
|
});
|
||||||
|
|
||||||
final ApiGateway gateway;
|
final ApiGateway gateway;
|
||||||
@@ -70,6 +72,9 @@ class RunsScreen extends StatefulWidget {
|
|||||||
/// App-level notification delivery for live attention transitions.
|
/// App-level notification delivery for live attention transitions.
|
||||||
final NotificationController? notifications;
|
final NotificationController? notifications;
|
||||||
|
|
||||||
|
/// The app's shared attention controller, mirrored on the shell's Runs tab.
|
||||||
|
final AttentionController? attention;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<RunsScreen> createState() => _RunsScreenState();
|
State<RunsScreen> createState() => _RunsScreenState();
|
||||||
}
|
}
|
||||||
@@ -193,6 +198,7 @@ class _RunsScreenState extends State<RunsScreen> {
|
|||||||
attentionStore: widget.attentionStore,
|
attentionStore: widget.attentionStore,
|
||||||
attentionNow: widget.attentionNow,
|
attentionNow: widget.attentionNow,
|
||||||
notifications: widget.notifications,
|
notifications: widget.notifications,
|
||||||
|
attention: widget.attention,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
|||||||
import '../../../core/api_gateway.dart';
|
import '../../../core/api_gateway.dart';
|
||||||
import '../../../ui/adaptive/host.dart';
|
import '../../../ui/adaptive/host.dart';
|
||||||
import '../../attention/notify/notification_controller.dart';
|
import '../../attention/notify/notification_controller.dart';
|
||||||
|
import '../../attention/runtime/attention_controller.dart';
|
||||||
import '../../attention/runtime/attention_store.dart';
|
import '../../attention/runtime/attention_store.dart';
|
||||||
import '../../attention/ui/needs_you_runs_heading.dart';
|
import '../../attention/ui/needs_you_runs_heading.dart';
|
||||||
import '../domain/run_models.dart';
|
import '../domain/run_models.dart';
|
||||||
@@ -19,6 +20,7 @@ class RunsList extends StatelessWidget {
|
|||||||
this.attentionStore = const SharedPreferencesAttentionStore(),
|
this.attentionStore = const SharedPreferencesAttentionStore(),
|
||||||
this.attentionNow,
|
this.attentionNow,
|
||||||
this.notifications,
|
this.notifications,
|
||||||
|
this.attention,
|
||||||
});
|
});
|
||||||
|
|
||||||
final RunsController controller;
|
final RunsController controller;
|
||||||
@@ -37,6 +39,9 @@ class RunsList extends StatelessWidget {
|
|||||||
/// App-level notification delivery; absent in list-only fixtures.
|
/// App-level notification delivery; absent in list-only fixtures.
|
||||||
final NotificationController? notifications;
|
final NotificationController? notifications;
|
||||||
|
|
||||||
|
/// The app's shared attention controller; absent in list-only fixtures.
|
||||||
|
final AttentionController? attention;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (controller.loading && controller.runs.isEmpty) {
|
if (controller.loading && controller.runs.isEmpty) {
|
||||||
@@ -108,6 +113,7 @@ class RunsList extends StatelessWidget {
|
|||||||
store: attentionStore,
|
store: attentionStore,
|
||||||
now: attentionNow,
|
now: attentionNow,
|
||||||
notifications: notifications,
|
notifications: notifications,
|
||||||
|
attention: attention,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'attention_badge.dart';
|
||||||
import 'destination.dart';
|
import 'destination.dart';
|
||||||
|
|
||||||
class AdaptiveShell extends StatefulWidget {
|
class AdaptiveShell extends StatefulWidget {
|
||||||
@@ -11,6 +12,7 @@ class AdaptiveShell extends StatefulWidget {
|
|||||||
this.destination,
|
this.destination,
|
||||||
this.onDestinationSelected,
|
this.onDestinationSelected,
|
||||||
this.onSearch,
|
this.onSearch,
|
||||||
|
this.attentionCount = 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Map<AppDestination, WidgetBuilder> destinationBodies;
|
final Map<AppDestination, WidgetBuilder> destinationBodies;
|
||||||
@@ -25,6 +27,10 @@ class AdaptiveShell extends StatefulWidget {
|
|||||||
/// shell tests and compositions without routing keep their tab set only.
|
/// shell tests and compositions without routing keep their tab set only.
|
||||||
final VoidCallback? onSearch;
|
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
|
@override
|
||||||
State<AdaptiveShell> createState() => _AdaptiveShellState();
|
State<AdaptiveShell> createState() => _AdaptiveShellState();
|
||||||
}
|
}
|
||||||
@@ -65,6 +71,17 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
|||||||
List<T> _items<T>(T Function(AppDestination) build) =>
|
List<T> _items<T>(T Function(AppDestination) build) =>
|
||||||
AppDestination.values.map(build).toList();
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final index = AppDestination.values.indexOf(_selected);
|
final index = AppDestination.values.indexOf(_selected);
|
||||||
@@ -108,6 +125,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
|||||||
_CupertinoSidebar(
|
_CupertinoSidebar(
|
||||||
selected: _selected,
|
selected: _selected,
|
||||||
onSelected: _select,
|
onSelected: _select,
|
||||||
|
attentionCount: widget.attentionCount,
|
||||||
),
|
),
|
||||||
Expanded(child: _destinationStack(contents, index)),
|
Expanded(child: _destinationStack(contents, index)),
|
||||||
],
|
],
|
||||||
@@ -117,11 +135,12 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
|||||||
Expanded(child: _destinationStack(contents, index)),
|
Expanded(child: _destinationStack(contents, index)),
|
||||||
CupertinoTabBar(
|
CupertinoTabBar(
|
||||||
currentIndex: index,
|
currentIndex: index,
|
||||||
onTap: (value) => _select(AppDestination.values[value]),
|
onTap: (value) =>
|
||||||
|
_select(AppDestination.values[value]),
|
||||||
items: _items((destination) {
|
items: _items((destination) {
|
||||||
final item = destinationDetails(destination);
|
final item = destinationDetails(destination);
|
||||||
return BottomNavigationBarItem(
|
return BottomNavigationBarItem(
|
||||||
icon: Icon(item.cupertinoIcon),
|
icon: _icon(destination, item.cupertinoIcon),
|
||||||
label: item.label,
|
label: item.label,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
@@ -155,7 +174,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
|||||||
destinations: _items((destination) {
|
destinations: _items((destination) {
|
||||||
final item = destinationDetails(destination);
|
final item = destinationDetails(destination);
|
||||||
return NavigationRailDestination(
|
return NavigationRailDestination(
|
||||||
icon: Icon(item.icon),
|
icon: _icon(destination, item.icon),
|
||||||
label: Text(item.label),
|
label: Text(item.label),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
@@ -172,7 +191,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
|||||||
destinations: _items((destination) {
|
destinations: _items((destination) {
|
||||||
final item = destinationDetails(destination);
|
final item = destinationDetails(destination);
|
||||||
return NavigationDestination(
|
return NavigationDestination(
|
||||||
icon: Icon(item.icon),
|
icon: _icon(destination, item.icon),
|
||||||
label: item.label,
|
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
|
/// The wide-window Cupertino destination list: the web's 200px rail with the
|
||||||
/// host's own grouped list controls.
|
/// host's own grouped list controls.
|
||||||
class _CupertinoSidebar extends StatelessWidget {
|
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 AppDestination selected;
|
||||||
final ValueChanged<AppDestination> onSelected;
|
final ValueChanged<AppDestination> onSelected;
|
||||||
|
final int attentionCount;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -215,7 +239,15 @@ class _CupertinoSidebar extends StatelessWidget {
|
|||||||
for (final destination in AppDestination.values)
|
for (final destination in AppDestination.values)
|
||||||
CupertinoListTile(
|
CupertinoListTile(
|
||||||
key: ValueKey('shell.destination.${destination.name}'),
|
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),
|
title: Text(destinationDetails(destination).label),
|
||||||
trailing: destination == selected
|
trailing: destination == selected
|
||||||
? Icon(
|
? Icon(
|
||||||
|
|||||||
@@ -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),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||||
|
|
||||||
|
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||||
|
import 'pipelines_app_test.dart' show pumpApp, replyList;
|
||||||
|
import 'pipelines_replies.dart';
|
||||||
|
|
||||||
|
/// The app lifts one attention controller above the destinations: the Runs
|
||||||
|
/// list seeds it when it loads and the app folds pushed `run_event` frames, so
|
||||||
|
/// the shell's Runs tab badge moves while another destination is shown.
|
||||||
|
void main() {
|
||||||
|
final needingAttention = RegExp('needing attention');
|
||||||
|
|
||||||
|
Finder badgeCount(String count) =>
|
||||||
|
find.descendant(of: find.byType(Badge), matching: find.text(count));
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'a run_event folded to waiting raises the Runs tab badge from Pipelines',
|
||||||
|
(tester) async {
|
||||||
|
final semantics = tester.ensureSemantics();
|
||||||
|
final channel = FakeChannel()..readyCompleter.complete();
|
||||||
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||||
|
final provider = PlatformRouteInformationProvider(
|
||||||
|
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
|
||||||
|
);
|
||||||
|
addTearDown(provider.dispose);
|
||||||
|
|
||||||
|
await pumpApp(
|
||||||
|
tester,
|
||||||
|
channel: channel,
|
||||||
|
client: client,
|
||||||
|
provider: provider,
|
||||||
|
);
|
||||||
|
await replyList(
|
||||||
|
tester,
|
||||||
|
channel,
|
||||||
|
runs: [
|
||||||
|
{
|
||||||
|
'id': 1,
|
||||||
|
'pipeline_id': 4,
|
||||||
|
'name': 'nightly',
|
||||||
|
'title': 'Nightly build',
|
||||||
|
'status': 'running',
|
||||||
|
'created_at': DateTime.now().toIso8601String(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
);
|
||||||
|
expect(find.text('Nightly build'), findsWidgets);
|
||||||
|
expect(tester.widget<Badge>(find.byType(Badge)).isLabelVisible, isFalse);
|
||||||
|
expect(find.bySemanticsLabel(needingAttention), findsNothing);
|
||||||
|
|
||||||
|
await tester.tap(find.text('Pipelines').last);
|
||||||
|
await tester.pump();
|
||||||
|
expect(provider.value.uri.path, '/pipelines');
|
||||||
|
await waitForRequest(tester, channel, 'list_pipelines');
|
||||||
|
expect(find.text('Nightly build'), findsNothing);
|
||||||
|
|
||||||
|
channel.incoming.add(
|
||||||
|
jsonEncode({'type': 'run_event', 'run_id': 1, 'status': 'waiting'}),
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(provider.value.uri.path, '/pipelines');
|
||||||
|
expect(tester.widget<Badge>(find.byType(Badge)).isLabelVisible, isTrue);
|
||||||
|
expect(badgeCount('1'), findsOneWidget);
|
||||||
|
expect(
|
||||||
|
find.bySemanticsLabel(RegExp('Notifications, 1 needing attention')),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
|
||||||
|
// The decision taken elsewhere clears the badge the same way.
|
||||||
|
channel.incoming.add(
|
||||||
|
jsonEncode({'type': 'run_event', 'run_id': 1, 'status': 'succeeded'}),
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump();
|
||||||
|
expect(tester.widget<Badge>(find.byType(Badge)).isLabelVisible, isFalse);
|
||||||
|
expect(badgeCount('1'), findsNothing);
|
||||||
|
expect(find.bySemanticsLabel(needingAttention), findsNothing);
|
||||||
|
semantics.dispose();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets('a new waiting run pushed before any list read is counted', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final channel = FakeChannel()..readyCompleter.complete();
|
||||||
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||||
|
final provider = PlatformRouteInformationProvider(
|
||||||
|
initialRouteInformation: RouteInformation(uri: Uri.parse('/settings')),
|
||||||
|
);
|
||||||
|
addTearDown(provider.dispose);
|
||||||
|
|
||||||
|
await pumpApp(tester, channel: channel, client: client, provider: provider);
|
||||||
|
expect(tester.widget<Badge>(find.byType(Badge)).isLabelVisible, isFalse);
|
||||||
|
|
||||||
|
channel.incoming.add(
|
||||||
|
jsonEncode({
|
||||||
|
'type': 'run_event',
|
||||||
|
'run_id': 9,
|
||||||
|
'pipeline_id': 4,
|
||||||
|
'name': 'nightly',
|
||||||
|
'title': 'Arrived while away',
|
||||||
|
'status': 'waiting',
|
||||||
|
'created_at': DateTime.now().toIso8601String(),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(provider.value.uri.path, '/settings');
|
||||||
|
expect(badgeCount('1'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||||
|
|
||||||
|
/// The Runs tab mirrors the attention count in every mount of both hosts:
|
||||||
|
/// Material rail and bottom bar, Cupertino sidebar and tab bar. Zero draws the
|
||||||
|
/// bare icon with no count and no attention semantics.
|
||||||
|
void main() {
|
||||||
|
final needingAttention = RegExp('Notifications, 3 needing attention');
|
||||||
|
final anyAttention = RegExp('needing attention');
|
||||||
|
|
||||||
|
Future<void> pumpShell(
|
||||||
|
WidgetTester tester, {
|
||||||
|
required double width,
|
||||||
|
required bool cupertino,
|
||||||
|
required int count,
|
||||||
|
}) async {
|
||||||
|
tester.view.physicalSize = Size(width, 900);
|
||||||
|
tester.view.devicePixelRatio = 1;
|
||||||
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
|
final shell = AdaptiveShell(cupertino: cupertino, attentionCount: count);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final width in [390.0, 1000.0]) {
|
||||||
|
final mount = width < 600 ? 'bottom bar' : 'rail';
|
||||||
|
|
||||||
|
testWidgets('Material $mount shows the count on the Runs tab', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final semantics = tester.ensureSemantics();
|
||||||
|
await pumpShell(tester, width: width, cupertino: false, count: 3);
|
||||||
|
expect(
|
||||||
|
find.byType(width < 600 ? NavigationBar : NavigationRail),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
final badge = find.byType(Badge);
|
||||||
|
expect(badge, findsOneWidget);
|
||||||
|
expect(tester.widget<Badge>(badge).isLabelVisible, isTrue);
|
||||||
|
expect(
|
||||||
|
find.descendant(of: badge, matching: find.text('3')),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
expect(find.bySemanticsLabel(needingAttention), findsOneWidget);
|
||||||
|
semantics.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Material $mount hides the badge at zero', (tester) async {
|
||||||
|
final semantics = tester.ensureSemantics();
|
||||||
|
await pumpShell(tester, width: width, cupertino: false, count: 0);
|
||||||
|
final badge = find.byType(Badge);
|
||||||
|
expect(badge, findsOneWidget);
|
||||||
|
expect(tester.widget<Badge>(badge).isLabelVisible, isFalse);
|
||||||
|
expect(
|
||||||
|
find.descendant(of: badge, matching: find.byType(Text)),
|
||||||
|
findsNothing,
|
||||||
|
);
|
||||||
|
expect(find.bySemanticsLabel(anyAttention), findsNothing);
|
||||||
|
semantics.dispose();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final width in [390.0, 1280.0]) {
|
||||||
|
final mount = width < 600 ? 'tab bar' : 'sidebar';
|
||||||
|
|
||||||
|
testWidgets('Cupertino $mount shows the count on the Runs item', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final semantics = tester.ensureSemantics();
|
||||||
|
await pumpShell(tester, width: width, cupertino: true, count: 3);
|
||||||
|
expect(
|
||||||
|
find.byType(CupertinoTabBar),
|
||||||
|
width < 600 ? findsOneWidget : findsNothing,
|
||||||
|
);
|
||||||
|
expect(find.byType(Badge), findsNothing, reason: 'no Material badge');
|
||||||
|
expect(find.text('3'), findsOneWidget);
|
||||||
|
expect(find.bySemanticsLabel(needingAttention), findsOneWidget);
|
||||||
|
semantics.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Cupertino $mount hides the count at zero', (tester) async {
|
||||||
|
final semantics = tester.ensureSemantics();
|
||||||
|
await pumpShell(tester, width: width, cupertino: true, count: 0);
|
||||||
|
expect(find.text('0'), findsNothing);
|
||||||
|
expect(find.bySemanticsLabel(anyAttention), findsNothing);
|
||||||
|
semantics.dispose();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('the badge stays visible from every destination', (tester) async {
|
||||||
|
await pumpShell(tester, width: 1000, cupertino: false, count: 2);
|
||||||
|
for (final label in ['Runs', 'Chat', 'Settings']) {
|
||||||
|
await tester.tap(find.text(label).last);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(
|
||||||
|
find.descendant(of: find.byType(Badge), matching: find.text('2')),
|
||||||
|
findsOneWidget,
|
||||||
|
reason: 'badge missing on $label',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user