203 lines
7.1 KiB
Dart
203 lines
7.1 KiB
Dart
import '../../../ui/theme/app_theme.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/foundation.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 EdgeInsetsDirectional.fromSTEB(20, 16, 8, 4),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Semantics(
|
|
header: true,
|
|
namesRoute: true,
|
|
child: Text(
|
|
attentionSheetTitle,
|
|
style: theme.textTheme.navTitleTextStyle,
|
|
),
|
|
),
|
|
),
|
|
CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: () => _close(context),
|
|
child: const Text(attentionCloseCopy),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
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),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|