Add mark as read action to notifications list

Users can now mark a notification as read via a popup menu on each list
item or by swiping left. Both actions call the backend API, remove the
item from the list, and show a snackbar confirmation. Swiping an already
read notification shows an error snackbar and bounces the item back.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-05-27 09:58:39 -04:00
co-authored by Claude Sonnet 4.6
parent 09b67c2707
commit 913bf0e839
4 changed files with 62 additions and 21 deletions
@@ -32,6 +32,34 @@ class _NotificationListState extends State<NotificationList> {
},
);
Future<bool> _markAsRead(
BuildContext context,
oott_model.Notification item,
) async {
if (!item.isNew) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Notification was already marked as read'),
behavior: SnackBarBehavior.floating,
showCloseIcon: true,
),
);
return false;
}
await BackendAPI.instance.markNotificationAsRead(item.id);
_pagingController.value = _pagingController.value.filterItems(
(n) => n.id != item.id,
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Event marked as read'),
behavior: SnackBarBehavior.floating,
showCloseIcon: true,
),
);
return true;
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -87,19 +115,8 @@ class _NotificationListState extends State<NotificationList> {
children: [
Dismissible(
key: UniqueKey(),
onDismissed: (direction) {
setState(() {
// _events!.removeAt(index);
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Event marked as read'),
behavior: SnackBarBehavior.floating,
showCloseIcon: true,
),
);
},
confirmDismiss: (direction) =>
_markAsRead(context, item),
background: Container(
color: Theme.of(
context,
@@ -114,7 +131,21 @@ class _NotificationListState extends State<NotificationList> {
'${FriendlyDateFormatter().format(item.createdOn)} - ${item.title}',
),
subtitle: Text(item.body, maxLines: 5),
trailing: Icon(Icons.more_vert),
trailing: PopupMenuButton<String>(
icon: const Icon(Icons.more_vert),
onSelected: (value) async {
if (value == 'mark_read') {
await _markAsRead(context, item);
}
},
itemBuilder: (context) => [
if (item.isNew)
const PopupMenuItem(
value: 'mark_read',
child: Text('Mark as read'),
),
],
),
onTap: () {},
isThreeLine: true,
),
+5
View File
@@ -66,6 +66,11 @@ class BackendAPI {
late String _apiKey;
late Dio _dio;
Future<void> markNotificationAsRead(int id) async {
print('About to call /notifications/$id');
await _dio.get('/notifications/$id');
}
Future<List<Notification>> listNotifications(bool? isNew, int offset) async {
print('About to call /notifications');