Files
oott/frontend/lib/notifications/notification_list.dart
T

72 lines
2.3 KiB
Dart
Raw Normal View History

2026-02-11 14:07:27 -05:00
import 'package:flutter/material.dart';
import '../utils/friendly_date_formatter.dart';
import '../model/notification.dart' as oott_model;
import '../utils/oott_api.dart';
2026-02-11 14:07:27 -05:00
class NotificationList extends StatefulWidget {
2026-02-11 18:31:12 -05:00
@override
_NotificationListState createState() => _NotificationListState();
2026-02-11 18:31:12 -05:00
}
class _NotificationListState extends State<NotificationList> {
bool _isLoading = true;
List<oott_model.Notification>? _events;
@override
void initState() {
super.initState();
_getData();
}
void _getData() async {
_events = await BackendAPI.instance.listNotifications();
_isLoading = false;
setState(() {});
}
2026-02-11 14:07:27 -05:00
@override
Widget build(BuildContext context) {
2026-02-11 18:31:12 -05:00
return Scaffold(
appBar: AppBar(title: const Text('Notifications')),
body: _isLoading
? const Center(child: CircularProgressIndicator())
: ListView.separated(
itemCount: _events!.length,
itemBuilder: (context, index) {
return Dismissible(
key: UniqueKey(),
onDismissed: (direction) {
setState(() {
_events!.removeAt(index);
});
2026-02-11 18:31:12 -05:00
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Event marked as read'),
behavior: SnackBarBehavior.floating,
showCloseIcon: true,
),
);
},
background: Container(
color: Theme.of(context).colorScheme.primaryContainer,
alignment: Alignment.center,
child: Icon(Icons.done),
),
child: ListTile(
leading: Icon(_events![index].notificationType.icon),
title: Text(
'${FriendlyDateFormatter().format(_events![index].createdOn)} - ${_events![index].title}',
),
subtitle: Text(_events![index].body),
trailing: Icon(Icons.more_vert),
onTap: () {},
),
);
},
separatorBuilder: (context, index) => Divider(),
2026-02-11 18:31:12 -05:00
),
2026-02-11 14:07:27 -05:00
);
}
}