feat: Improve task data fetching by clearing grouped tasks on new load and preventing duplicates

This commit is contained in:
Vaibhav Surve 2025-11-04 14:52:17 +05:30
parent ac7a75c92f
commit 82c2cc3c58

View File

@ -134,11 +134,24 @@ class DailyTaskController extends GetxController {
); );
if (response != null && response.isNotEmpty) { if (response != null && response.isNotEmpty) {
if (!isLoadMore) {
groupedDailyTasks.clear();
}
for (var task in response) { for (var task in response) {
final assignmentDateKey = final assignmentDateKey =
task.assignmentDate.toIso8601String().split('T')[0]; task.assignmentDate.toIso8601String().split('T')[0];
groupedDailyTasks.putIfAbsent(assignmentDateKey, () => []).add(task);
// Initialize list if not present
groupedDailyTasks.putIfAbsent(assignmentDateKey, () => []);
// Only add task if it doesn't already exist (avoid duplicates)
if (!groupedDailyTasks[assignmentDateKey]!
.any((t) => t.id == task.id)) {
groupedDailyTasks[assignmentDateKey]!.add(task);
}
} }
dailyTasks = groupedDailyTasks.values.expand((list) => list).toList(); dailyTasks = groupedDailyTasks.values.expand((list) => list).toList();
currentPage = pageNumber; currentPage = pageNumber;
} else { } else {