Files
oott/frontend/lib/home/notification_card.dart
T
rzuastiandClaude Opus 4.8 9367c359d7 Polish frontend: design tokens, theming, AppBar titles, empty/loading states
Frontend usability and aesthetics pass across web and mobile:

- Add shared layout tokens (theme/dimens.dart: Insets + Breakpoints) and
  replace magic-number spacing and per-file breakpoint consts.
- Route both themes through buildAppTheme (theme/theme_builder.dart): explicit
  useMaterial3 and a shared branded textTheme (Barlow Condensed for
  display/headline/title styles); logo now reads its style from the theme.
- Move screen titles into the shared AppBar (route-derived) and drop the
  redundant in-body headers; upgrade Settings buttons to M3 FilledButton.
- Add reusable EmptyState and skeleton loaders; Devices empty state links to
  scanner status, notifications get filter-aware messages.
- Add a first-run welcome intro and Save-disabled helper text in Settings.
- Make device Filter/Sort adaptive: bottom sheet on phones, dialog on wide.
- Collapse the device-list filter chips and Sort/Filter buttons into one row;
  rename the home Scanners card title and align its style.

Tests: add EmptyState/skeleton widget tests and Settings first-run cases;
update tests for the FilledButton swap and relocated titles. 89 passing,
dart analyze clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 08:39:37 -04:00

110 lines
3.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../model/notification.dart' as oott_model;
import '../theme/dimens.dart';
import '../utils/friendly_date_formatter.dart';
class NotificationCard extends StatefulWidget {
final oott_model.Notification item;
final FriendlyDateFormatter formatter;
final Future<bool> Function(bool read) onSetRead;
const NotificationCard({
required this.item,
required this.formatter,
required this.onSetRead,
super.key,
});
@override
State<NotificationCard> createState() => _NotificationCardState();
}
class _NotificationCardState extends State<NotificationCard> {
bool _expanded = false;
Widget _buildActions(BuildContext context) {
return Padding(
padding: const EdgeInsets.fromLTRB(Insets.sm, 0, Insets.sm, Insets.sm),
child: OverflowBar(
alignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => widget.onSetRead(widget.item.isNew),
child: Text(widget.item.isNew ? 'Mark as read' : 'Mark as unread'),
),
if (widget.item.macAddress != null)
TextButton.icon(
icon: const Icon(Icons.open_in_new),
label: const Text('View device'),
onPressed: () async {
if (widget.item.isNew) await widget.onSetRead(true);
if (context.mounted) {
context.push('/devices/${widget.item.macAddress}');
}
},
),
],
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Card(
color: widget.item.isNew ? theme.colorScheme.secondaryContainer : null,
child: Dismissible(
key: ValueKey(widget.item.id),
confirmDismiss: (direction) =>
widget.onSetRead(direction != DismissDirection.startToEnd),
background: Container(
color: theme.colorScheme.tertiaryContainer,
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: Insets.lg),
child: const Icon(Icons.mark_email_unread),
),
secondaryBackground: Container(
color: theme.colorScheme.primaryContainer,
alignment: Alignment.centerRight,
padding: const EdgeInsets.only(right: Insets.lg),
child: const Icon(Icons.done),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ListTile(
leading: Icon(
widget.item.notificationType.icon,
color: widget.item.isNew ? theme.colorScheme.primary : null,
),
title: Text(
'${widget.formatter.format(widget.item.createdOn)} - ${widget.item.title}',
style: widget.item.isNew
? const TextStyle(fontWeight: FontWeight.bold)
: null,
),
subtitle: Text(
widget.item.body,
maxLines: _expanded ? null : 2,
overflow: _expanded
? TextOverflow.visible
: TextOverflow.ellipsis,
),
onTap: () => setState(() => _expanded = !_expanded),
),
AnimatedSize(
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
child: _expanded
? _buildActions(context)
: const SizedBox.shrink(),
),
],
),
),
);
}
}