diff --git a/lib/features/admin/presentation/complaints_page.dart b/lib/features/admin/presentation/complaints_page.dart index 453f639..87dff5b 100644 --- a/lib/features/admin/presentation/complaints_page.dart +++ b/lib/features/admin/presentation/complaints_page.dart @@ -46,6 +46,16 @@ class _ComplaintsPageState extends State { uid = await authService.getUserUid(idToken!); } + void sortComplaintsByDate({bool descending = true}) { + complaints.sort((a, b) { + if (descending) { + return b.date.compareTo(a.date); // Mới nhất trước + } else { + return a.date.compareTo(b.date); // Cũ nhất trước + } + }); +} + void toggleSelectAllButton() { if (chosenList.isEmpty) { for (Complaint c in complaints) { @@ -76,7 +86,7 @@ class _ComplaintsPageState extends State { ); getUidAndIdtoken(); _fetchComplaints(); - + } @override @@ -106,6 +116,7 @@ class _ComplaintsPageState extends State { if (mounted) { setState(() { complaints = complaintsFetched; + sortComplaintsByDate(); _isLoading = false; }); } diff --git a/lib/features/resident/presentation/complaints_page.dart b/lib/features/resident/presentation/complaints_page.dart index 6d17c1a..f46ca13 100644 --- a/lib/features/resident/presentation/complaints_page.dart +++ b/lib/features/resident/presentation/complaints_page.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -// import 'dart:math'; +import 'dart:math'; import 'package:fluentui_system_icons/fluentui_system_icons.dart'; import '../domain/r_complaints.dart'; import 'package:intl/intl.dart'; @@ -89,6 +89,8 @@ class _ComplaintsPageState extends State { return formattedDate; } + + TextEditingController titleAddController = TextEditingController(); TextEditingController descriptionController = TextEditingController(); showDialog( @@ -211,7 +213,7 @@ class _ComplaintsPageState extends State { date: convertTime(), id: '123', isFlagged: false, - bgColor:complaints.isEmpty?Colors.green: complaints[0].bgColor); + bgColor:complaints.isEmpty?generateRandomColor(): complaints[0].bgColor); _addComplaint(complaintData, newComplaint); Navigator.pop(context); // Thực hiện logic, rồi đóng dialog }, @@ -222,6 +224,18 @@ class _ComplaintsPageState extends State { }, ); } + final List colorPalette = [ + const Color(0xffd69ca5), + const Color(0xff94c8d4), + const Color(0xffd696c0), + const Color(0xffa6e9ed), + const Color(0xff9ad29a), + const Color(0xffcecccb) + ]; + Color generateRandomColor() { + final randomColor = colorPalette[Random().nextInt(colorPalette.length)]; + return randomColor; + } @override void initState() {