2026-02-11 14:07:27 -05:00
|
|
|
import 'package:flutter/material.dart';
|
2026-02-27 12:28:16 -05:00
|
|
|
import '../utils/friendly_date_formatter.dart';
|
2026-03-02 13:59:50 -05:00
|
|
|
import '../model/notification.dart' as oott_model;
|
2026-02-27 12:28:16 -05:00
|
|
|
import '../utils/oott_api.dart';
|
2026-02-11 14:07:27 -05:00
|
|
|
|
2026-03-02 13:59:50 -05:00
|
|
|
class NotificationList extends StatefulWidget {
|
2026-02-11 18:31:12 -05:00
|
|
|
@override
|
2026-03-02 13:59:50 -05:00
|
|
|
_NotificationListState createState() => _NotificationListState();
|
2026-02-11 18:31:12 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-02 13:59:50 -05:00
|
|
|
class _NotificationListState extends State<NotificationList> {
|
2026-02-27 12:28:16 -05:00
|
|
|
bool _isLoading = true;
|
2026-03-02 13:59:50 -05:00
|
|
|
List<oott_model.Notification>? _events;
|
2026-02-27 12:28:16 -05:00
|
|
|
|
|
|
|
|
@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(
|
2026-03-02 13:59:50 -05:00
|
|
|
appBar: AppBar(title: const Text('Notifications')),
|
2026-02-27 12:28:16 -05:00
|
|
|
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
|
|
|
|
2026-02-27 12:28:16 -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
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|