Remove Cupertino attention branches

Keep the reviewed attention surfaces on their Material implementations while preserving public cupertino parameters for remaining callers. Remove the unreachable Cupertino sheet and narrow tests to the Material path.
This commit is contained in:
2026-11-11 01:31:14 +00:00
parent 37cf9472c2
commit 968e3e908a
16 changed files with 792 additions and 1157 deletions
@@ -1,9 +1,7 @@
import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/attention_models.dart';
import 'needs_you_keys.dart';
import 'needs_you_sheet.dart';
@@ -43,8 +41,8 @@ class NeedsYouBell extends StatefulWidget {
final ValueChanged<AttentionEntry> onDismiss;
final ValueChanged<List<AttentionEntry>> onClearAll;
/// Forces the native host in tests and fixtures; otherwise the ambient
/// [usesCupertinoHost] decides.
/// Retained for callers that still pass it; the bell is the Material action
/// whether this is set or not.
final bool? cupertino;
@override
@@ -150,17 +148,14 @@ class _NeedsYouBellState extends State<NeedsYouBell> {
@override
Widget build(BuildContext context) {
final native = widget.cupertino ?? usesCupertinoHost(context);
final label = attentionBadgeLabel(widget.entries.length);
final action = native ? _cupertino(context) : _material(context, label);
final semantics = Semantics(
label: label,
button: true,
onTap: _open,
excludeSemantics: true,
child: action,
child: _material(label),
);
if (native) return semantics;
// The reserved badge room is outside the semantics box, so the focus
// rectangle stays the size of the action rather than the empty end room.
return Padding(
@@ -169,57 +164,18 @@ class _NeedsYouBellState extends State<NeedsYouBell> {
);
}
Widget _material(BuildContext context, String label) {
Widget _material(String label) {
return IconButton(
key: attentionBellKey,
focusNode: _focus,
tooltip: label,
onPressed: _open,
icon: _badged(
context,
hostCupertino: false,
icon: const Icon(Icons.notifications_outlined),
),
icon: _badged(const Icon(Icons.notifications_outlined)),
);
}
Widget _cupertino(BuildContext context) {
final theme = CupertinoTheme.of(context);
// The whole 44pt target and no extra padding, like every bar action.
return CupertinoButton(
key: attentionBellKey,
focusNode: _focus,
padding: EdgeInsets.zero,
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
onPressed: _open,
child: _badged(
context,
hostCupertino: true,
icon: const Icon(CupertinoIcons.bell),
textStyle: theme.textTheme.tabLabelTextStyle,
),
);
}
Widget _badged(
BuildContext context, {
required bool hostCupertino,
required Widget icon,
TextStyle? textStyle,
}) {
Widget _badged(Widget icon) {
final count = widget.entries.length;
// No native Cupertino badge exists; the framework Badge is used with the
// host's semantic red and the host's smallest text role.
if (hostCupertino && count > 0) {
return Badge.count(
key: attentionBadgeKey,
count: count,
textStyle: textStyle,
backgroundColor: CupertinoColors.systemRed.resolveFrom(context),
textColor: CupertinoColors.white,
child: icon,
);
}
if (count > 0) {
return Badge.count(key: attentionBadgeKey, count: count, child: icon);
}
@@ -6,13 +6,13 @@ const attentionBellKey = ValueKey<String>('attention-bell');
/// The visible count badge. Absent when nothing needs the operator.
const attentionBadgeKey = ValueKey<String>('attention-badge');
/// The open sheet itself, whichever native host draws it.
/// The open sheet itself.
const attentionSheetKey = ValueKey<String>('attention-sheet');
/// The honest empty line shown when the open snapshot has no entries.
const attentionEmptyKey = ValueKey<String>('attention-empty');
/// The header's Done action, which closes the sheet on both hosts.
/// The header's Done action, which closes the sheet.
const attentionDoneKey = ValueKey<String>('attention-done');
/// The bulk dismissal action, present only while the snapshot has entries.
@@ -15,8 +15,7 @@ import 'needs_you_bell.dart';
/// It owns the live attention state for this destination: [rows] are the
/// already-loaded `list_runs` summaries and [frames] is the shared gateway's
/// unsolicited stream, so it never polls or issues an attention request. The
/// bell has no built-in host choice; the ambient app host (or [cupertino] in a
/// fixture) selects the native Material or Cupertino action and sheet.
/// bell is always the Material action and sheet.
class NeedsYouRunsHeading extends StatefulWidget {
const NeedsYouRunsHeading({
super.key,
@@ -49,7 +48,8 @@ class NeedsYouRunsHeading extends StatefulWidget {
/// Injected clock for deterministic local-day windows.
final DateTime Function()? now;
/// Forces the native host in tests and fixtures.
/// Retained for callers that still pass it; the heading is always the
/// Material bell whether this is set or not.
final bool? cupertino;
/// The app-level notification capability. Absent in fixtures that only draw
@@ -1,10 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/attention_models.dart';
import 'needs_you_sheet_cupertino.dart';
import 'needs_you_sheet_material.dart';
/// Opens the native `Needs you` sheet over the live [entries].
@@ -17,8 +14,8 @@ import 'needs_you_sheet_material.dart';
///
/// The sheet stays open after Dismiss and Clear all, so several rows can be
/// dealt with in one visit. Choosing a row closes it; Escape, the barrier and
/// system back are native route behaviour. The caller supplies the native host
/// explicitly when it already knows it; otherwise the ambient app host decides.
/// system back are native route behaviour. The sheet is always the Material
/// bottom sheet; [cupertino] is retained for callers that still pass it.
Future<void> showNeedsYouSheet({
required BuildContext context,
required ValueListenable<List<AttentionEntry>> entries,
@@ -28,19 +25,6 @@ Future<void> showNeedsYouSheet({
bool? cupertino,
}) {
final snapshot = attentionDismissalSnapshot(entries.value);
final native = cupertino ?? usesCupertinoHost(context);
if (native) {
return showCupertinoModalPopup<void>(
context: context,
builder: (_) => CupertinoNeedsYouSheet(
entries: entries,
snapshot: snapshot,
onOpen: onOpen,
onDismiss: onDismiss,
onClearAll: onClearAll,
),
);
}
return showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
@@ -1,190 +0,0 @@
import '../../../ui/theme/app_theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import '../../../ui/layout/app_sheet_header.dart';
import 'attention_status_icon.dart';
import '../domain/attention_models.dart';
import 'needs_you_copy.dart';
import 'needs_you_keys.dart';
/// The Cupertino popup body of the `Needs you` surface.
///
/// It reads as a native action-sheet style grouped list: an inset-grouped iOS
/// list in a [CupertinoPopupSurface], with a Close action, one grouped row per
/// live entry and a separate Clear-all group. Dismissing and Clear all leave the
/// sheet open and redraw it, matching the browser; [snapshot] is the set Clear
/// all may remove, so a later arrival is shown but never cleared by this visit.
/// Rows use host text roles without a line cap so a long label and description
/// wrap at a narrow, scaled width.
class CupertinoNeedsYouSheet extends StatelessWidget {
const CupertinoNeedsYouSheet({
super.key,
required this.entries,
required this.snapshot,
required this.onOpen,
required this.onDismiss,
required this.onClearAll,
});
/// The caller's current rows; a dismissal removed there redraws the sheet.
final ValueListenable<List<AttentionEntry>> entries;
/// The identities captured when the sheet opened, all Clear all may remove.
final List<AttentionEntry> snapshot;
final ValueChanged<AttentionEntry> onOpen;
final ValueChanged<AttentionEntry> onDismiss;
final ValueChanged<List<AttentionEntry>> onClearAll;
void _close(BuildContext context) => Navigator.of(context).pop();
void _open(BuildContext context, AttentionEntry entry) {
_close(context);
onOpen(entry);
}
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<List<AttentionEntry>>(
valueListenable: entries,
builder: (context, rows, _) => _sheet(context, rows),
);
}
Widget _sheet(BuildContext context, List<AttentionEntry> rows) {
final theme = CupertinoTheme.of(context);
final dismissLabels = attentionDismissLabels(rows);
return SafeArea(
key: attentionSheetKey,
top: false,
child: Padding(
padding: const EdgeInsets.all(8),
child: CupertinoPopupSurface(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.only(top: 8),
child: AppSheetHeader(
title: attentionSheetTitle,
cupertino: true,
doneKey: attentionDoneKey,
onDone: () => _close(context),
),
),
if (rows.isEmpty)
Padding(
key: attentionEmptyKey,
padding: const EdgeInsetsDirectional.fromSTEB(20, 8, 20, 24),
child: Text(
attentionEmptyCopy,
style: theme.textTheme.textStyle.copyWith(
color: CupertinoColors.secondaryLabel.resolveFrom(
context,
),
),
),
)
else
Flexible(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CupertinoListSection.insetGrouped(
backgroundColor: AppColors.groupedBackground,
children: [
for (final entry in rows)
_AttentionRow(
key: attentionRowKey(entry.key),
entry: entry,
dismissLabel: dismissLabels[entry.key]!,
onOpen: () => _open(context, entry),
onDismiss: () => onDismiss(entry),
),
],
),
CupertinoListSection.insetGrouped(
backgroundColor: AppColors.groupedBackground,
children: [
CupertinoListTile(
key: attentionClearAllKey,
title: Center(child: Text(attentionClearAllCopy)),
onTap: () => onClearAll(snapshot),
),
],
),
],
),
),
),
],
),
),
),
);
}
}
/// One native grouped row: an open action over the host's text roles and a
/// separate Dismiss control named after the row it removes. It deliberately does
/// not use [CupertinoListTile], whose single-line title/subtitle would truncate a
/// long scaled label.
class _AttentionRow extends StatelessWidget {
const _AttentionRow({
super.key,
required this.entry,
required this.dismissLabel,
required this.onOpen,
required this.onDismiss,
});
final AttentionEntry entry;
final String dismissLabel;
final VoidCallback onOpen;
final VoidCallback onDismiss;
@override
Widget build(BuildContext context) {
final theme = CupertinoTheme.of(context);
final secondary = theme.textTheme.textStyle.copyWith(
color: CupertinoColors.secondaryLabel.resolveFrom(context),
);
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 10, 8, 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 4),
child: attentionStatusIcon(entry),
),
const SizedBox(width: 12),
Expanded(
child: CupertinoButton(
padding: EdgeInsets.zero,
alignment: AlignmentDirectional.centerStart,
onPressed: onOpen,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(entry.label, style: theme.textTheme.textStyle),
const SizedBox(height: 4),
Text(attentionRowDescription(entry), style: secondary),
],
),
),
),
CupertinoButton(
key: attentionDismissKey(entry.key),
padding: EdgeInsets.zero,
onPressed: onDismiss,
child: Icon(CupertinoIcons.xmark, semanticLabel: dismissLabel),
),
],
),
);
}
}
@@ -1,10 +1,8 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../notify/notification_models.dart';
/// The permission tile's root, so a caller can find it whichever host draws it.
/// The permission tile's root, so a caller can find it.
const notificationTileKey = ValueKey<String>('notification-permission-tile');
/// The explicit-gesture Enable action, present only when a request is possible.
@@ -44,28 +42,20 @@ class NotificationPermissionTile extends StatelessWidget {
/// request would be possible.
final VoidCallback? onRequest;
/// Forces the native host in tests and fixtures; otherwise the ambient
/// [usesCupertinoHost] decides.
/// Retained for callers that still pass it; the tile is the Material row
/// whether this is set or not.
final bool? cupertino;
@override
Widget build(BuildContext context) {
final view = notificationPermissionView(state, asked: asked);
final native = cupertino ?? usesCupertinoHost(context);
final action = view.canRequest && onRequest != null
? _action(native, view.actionLabel!, onRequest!)
? _action(view.actionLabel!, onRequest!)
: null;
final titleStyle = native
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.bodyLarge;
final helperStyle = native
? CupertinoTheme.of(context).textTheme.textStyle.copyWith(
fontSize: 15,
color: CupertinoColors.secondaryLabel.resolveFrom(context),
)
: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
final titleStyle = Theme.of(context).textTheme.bodyLarge;
final helperStyle = Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
// One compact row: the state, one short helper line and Enable at the
// end. The full sentence for the state is what a screen reader hears.
// The Settings section supplies the `Notifications` heading.
@@ -97,20 +87,13 @@ class NotificationPermissionTile extends StatelessWidget {
}
/// A short `Enable`, named in full for assistive technology.
Widget _action(bool native, String label, VoidCallback onRequest) {
Widget _action(String label, VoidCallback onRequest) {
const text = Text(notificationEnableShortLabel);
final Widget button = native
? CupertinoButton.tinted(
key: notificationEnableKey,
sizeStyle: CupertinoButtonSize.small,
onPressed: onRequest,
child: text,
)
: FilledButton.tonal(
key: notificationEnableKey,
onPressed: onRequest,
child: text,
);
final Widget button = FilledButton.tonal(
key: notificationEnableKey,
onPressed: onRequest,
child: text,
);
return Semantics(
button: true,
label: label,