change date format in notification screen
This commit is contained in:
parent
65b97c4f73
commit
3c14095b22
@ -1,5 +1,4 @@
|
|||||||
import 'package:cheminova/models/notification_list_response.dart';
|
import 'package:cheminova/models/notification_list_response.dart';
|
||||||
import 'package:cheminova/models/rejected_applicaton_response.dart';
|
|
||||||
import 'package:cheminova/provider/notification_provider.dart';
|
import 'package:cheminova/provider/notification_provider.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:cheminova/widgets/common_background.dart';
|
import 'package:cheminova/widgets/common_background.dart';
|
||||||
@ -8,7 +7,6 @@ import 'package:cheminova/widgets/common_app_bar.dart';
|
|||||||
import 'package:cheminova/widgets/common_elevated_button.dart';
|
import 'package:cheminova/widgets/common_elevated_button.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../provider/rejected_provider.dart';
|
|
||||||
|
|
||||||
class NotificationScreen extends StatefulWidget {
|
class NotificationScreen extends StatefulWidget {
|
||||||
const NotificationScreen({super.key});
|
const NotificationScreen({super.key});
|
||||||
@ -59,7 +57,8 @@ class NotificationScreenState extends State<NotificationScreen> {
|
|||||||
: MyListView(value: value),
|
: MyListView(value: value),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,13 +86,40 @@ class MyListView extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
// Group notifications by date
|
||||||
|
Map<String, List<Notifications>> groupedNotifications = {};
|
||||||
|
|
||||||
|
for (var notification in value.notificationList) {
|
||||||
|
String date = DateFormat("dd MMM yyyy").format(DateTime.parse(notification.createdAt ?? ''));
|
||||||
|
if (!groupedNotifications.containsKey(date)) {
|
||||||
|
groupedNotifications[date] = [];
|
||||||
|
}
|
||||||
|
groupedNotifications[date]!.add(notification);
|
||||||
|
}
|
||||||
|
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
padding: const EdgeInsets.only(top: 15),
|
padding: const EdgeInsets.only(top: 15),
|
||||||
itemCount: value.notificationList.length,
|
itemCount: groupedNotifications.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
Notifications item = value.notificationList[index];
|
String date = groupedNotifications.keys.elementAt(index);
|
||||||
|
List<Notifications> notificationsForDate = groupedNotifications[date]!;
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 10, left: 10, right: 10),
|
padding: const EdgeInsets.only(bottom: 10, left: 10, right: 10),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// Display the date once
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 8.0),
|
||||||
|
child: Text(
|
||||||
|
date,
|
||||||
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Display notifications for the date
|
||||||
|
...notificationsForDate.map((item) => Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 10),
|
||||||
child: ExpansionTile(
|
child: ExpansionTile(
|
||||||
collapsedBackgroundColor: Colors.white,
|
collapsedBackgroundColor: Colors.white,
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
@ -102,14 +128,10 @@ class MyListView extends StatelessWidget {
|
|||||||
item.title ?? '',
|
item.title ?? '',
|
||||||
style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w500),
|
style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w500),
|
||||||
),
|
),
|
||||||
subtitle: Column(
|
subtitle: Text(item.msg ?? ''),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text((DateFormat("dd/MMM/yyyy")
|
|
||||||
.format(DateTime.parse(item.createdAt ?? '')))),
|
|
||||||
Text(item.msg ?? ''),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
)),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user