import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'attention_status_icon.dart'; import '../domain/attention_models.dart'; import 'needs_you_copy.dart'; import 'needs_you_keys.dart'; /// The Material bottom-sheet body of the `Needs you` surface. /// /// It draws the live rows it is given: the pure model's order, one native /// `ListTile` per entry, each row opening its run while its trailing control /// dismisses only that identity. 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. The list /// stays scrollable so a long label or a large text scale cannot push the /// actions off the sheet. class MaterialNeedsYouSheet extends StatelessWidget { const MaterialNeedsYouSheet({ 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> entries; /// The identities captured when the sheet opened, all Clear all may remove. final List snapshot; final ValueChanged onOpen; final ValueChanged onDismiss; final ValueChanged> onClearAll; void _open(BuildContext context, AttentionEntry entry) { Navigator.of(context).pop(); onOpen(entry); } @override Widget build(BuildContext context) { return ValueListenableBuilder>( valueListenable: entries, builder: (context, rows, _) => _sheet(context, rows), ); } Widget _sheet(BuildContext context, List rows) { final theme = Theme.of(context); final dismissLabels = attentionDismissLabels(rows); return SafeArea( key: attentionSheetKey, child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Padding( padding: const EdgeInsetsDirectional.fromSTEB(24, 0, 12, 4), child: Row( children: [ Expanded( child: Semantics( header: true, namesRoute: true, child: Text( attentionSheetTitle, style: theme.textTheme.titleLarge, ), ), ), if (rows.isNotEmpty) TextButton( key: attentionClearAllKey, onPressed: () => onClearAll(snapshot), child: const Text(attentionClearAllCopy), ), ], ), ), if (rows.isEmpty) Padding( key: attentionEmptyKey, padding: const EdgeInsetsDirectional.fromSTEB(24, 8, 24, 24), child: Text( attentionEmptyCopy, style: theme.textTheme.bodyMedium?.copyWith( color: theme.colorScheme.onSurfaceVariant, ), ), ) else Flexible( child: ListView.separated( shrinkWrap: true, padding: const EdgeInsets.only(bottom: 8), itemCount: rows.length, separatorBuilder: (_, _) => const Divider(height: 1), itemBuilder: (context, index) { final entry = rows[index]; return ListTile( key: attentionRowKey(entry.key), // The run status glyph, as the web's attention row. leading: attentionStatusIcon(entry), title: Text(entry.label), subtitle: Text(attentionRowDescription(entry)), trailing: IconButton( key: attentionDismissKey(entry.key), tooltip: dismissLabels[entry.key], onPressed: () => onDismiss(entry), icon: const Icon(Icons.close), ), onTap: () => _open(context, entry), ); }, ), ), ], ), ); } }