2026-02-11 14:07:27 -05:00
|
|
|
import 'package:flutter/material.dart';
|
2026-03-04 11:05:24 -05:00
|
|
|
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
|
|
|
|
|
2026-03-02 13:59:50 -05:00
|
|
|
import '../model/notification.dart' as oott_model;
|
2026-03-04 11:05:24 -05:00
|
|
|
import '../utils/friendly_date_formatter.dart';
|
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-03-04 11:05:24 -05:00
|
|
|
const NotificationList({super.key});
|
|
|
|
|
|
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-03-04 16:22:00 -05:00
|
|
|
int _filterChoice = 1; // 1 => Only new, 2=> Only old, 3=> All
|
|
|
|
|
|
|
|
|
|
late final _pagingController = PagingController<int, oott_model.Notification>(
|
2026-03-04 11:05:24 -05:00
|
|
|
getNextPageKey: (state) => state.lastPageIsEmpty
|
|
|
|
|
? null
|
|
|
|
|
: (state.items == null ? 0 : state.items?.length),
|
2026-03-04 16:22:00 -05:00
|
|
|
fetchPage: (pageKey) {
|
|
|
|
|
bool? isNew;
|
|
|
|
|
|
|
|
|
|
if (_filterChoice == 1) {
|
|
|
|
|
isNew = true;
|
|
|
|
|
} else if (_filterChoice == 2) {
|
|
|
|
|
isNew = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BackendAPI.instance.listNotifications(isNew, pageKey);
|
|
|
|
|
},
|
2026-03-04 11:05:24 -05:00
|
|
|
);
|
2026-02-27 12:28:16 -05:00
|
|
|
|
2026-03-04 16:22:00 -05:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(title: const Text('Notifications')),
|
|
|
|
|
body:
|
|
|
|
|
// Paginated list start
|
|
|
|
|
PagingListener(
|
|
|
|
|
controller: _pagingController,
|
|
|
|
|
builder: (context, state, fetchNextPage) => CustomScrollView(
|
|
|
|
|
slivers: [
|
|
|
|
|
// Filters go here
|
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
|
child: Container(
|
|
|
|
|
height: 50,
|
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
|
child: Wrap(
|
|
|
|
|
spacing: 8.0,
|
|
|
|
|
children: [
|
|
|
|
|
ChoiceChip(
|
|
|
|
|
label: Text('New'),
|
|
|
|
|
selected: _filterChoice == 1,
|
|
|
|
|
onSelected: (bool selected) {
|
|
|
|
|
_filterChoice = 1;
|
|
|
|
|
_pagingController.refresh();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
ChoiceChip(
|
|
|
|
|
label: Text('Old'),
|
|
|
|
|
selected: _filterChoice == 2,
|
|
|
|
|
onSelected: (bool selected) {
|
|
|
|
|
_filterChoice = 2;
|
|
|
|
|
_pagingController.refresh();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
ChoiceChip(
|
|
|
|
|
label: Text('All'),
|
|
|
|
|
selected: _filterChoice == 3,
|
|
|
|
|
onSelected: (bool selected) {
|
|
|
|
|
_filterChoice = 3;
|
|
|
|
|
_pagingController.refresh();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
PagedSliverList<int, oott_model.Notification>(
|
|
|
|
|
state: state,
|
|
|
|
|
fetchNextPage: fetchNextPage,
|
|
|
|
|
builderDelegate: PagedChildBuilderDelegate(
|
|
|
|
|
itemBuilder: (context, item, index) {
|
|
|
|
|
return Column(
|
|
|
|
|
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,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
background: Container(
|
|
|
|
|
color: Theme.of(
|
|
|
|
|
context,
|
|
|
|
|
).colorScheme.primaryContainer,
|
|
|
|
|
alignment: Alignment.center,
|
|
|
|
|
child: Icon(Icons.done),
|
|
|
|
|
),
|
|
|
|
|
child: ListTile(
|
|
|
|
|
// tileColor: item.isNew ? Colors.amber : null,
|
|
|
|
|
leading: Icon(item.notificationType.icon),
|
|
|
|
|
title: Text(
|
|
|
|
|
'${FriendlyDateFormatter().format(item.createdOn)} - ${item.title}',
|
|
|
|
|
),
|
|
|
|
|
subtitle: Text(item.body, maxLines: 5),
|
|
|
|
|
trailing: Icon(Icons.more_vert),
|
|
|
|
|
onTap: () {},
|
|
|
|
|
isThreeLine: true,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Divider(),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
// Paginated list end
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 12:28:16 -05:00
|
|
|
@override
|
2026-03-04 11:05:24 -05:00
|
|
|
void dispose() {
|
|
|
|
|
_pagingController.dispose();
|
|
|
|
|
super.dispose();
|
2026-02-27 12:28:16 -05:00
|
|
|
}
|
2026-02-11 14:07:27 -05:00
|
|
|
}
|