Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/app/modules/home/controllers/widget.controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,21 @@ class WidgetController extends GetxController {
case 'Due till-':
return b.due!.compareTo(a.due!);
case 'Priority-':
return a.priority!.compareTo(b.priority!);
final priorityCompare = a.priority!.compareTo(b.priority!);
if (priorityCompare != 0) return priorityCompare;
// If priorities are equal, sort by due date
if (a.due == null && b.due == null) return 0;
if (a.due == null) return 1;
if (b.due == null) return -1;
return a.due!.compareTo(b.due!);
case 'Priority+':
return b.priority!.compareTo(a.priority!);
final priorityCompare = b.priority!.compareTo(a.priority!);
if (priorityCompare != 0) return priorityCompare;
// If priorities are equal, sort by due date
if (a.due == null && b.due == null) return 0;
if (a.due == null) return 1;
if (b.due == null) return -1;
return a.due!.compareTo(b.due!);
case 'Project+':
return a.project!.compareTo(b.project!);
case 'Project-':
Expand Down
16 changes: 14 additions & 2 deletions lib/app/modules/home/views/show_tasks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,21 @@ class TaskViewBuilder extends StatelessWidget {
case 'Due till-':
return b.due!.compareTo(a.due!);
case 'Priority-':
return b.priority!.compareTo(a.priority!);
final priorityCompare = b.priority!.compareTo(a.priority!);
if (priorityCompare != 0) return priorityCompare;
// If priorities are equal, sort by due date
if (a.due == null && b.due == null) return 0;
if (a.due == null) return 1;
if (b.due == null) return -1;
return a.due!.compareTo(b.due!);
case 'Priority+':
return a.priority!.compareTo(b.priority!);
final priorityCompare = a.priority!.compareTo(b.priority!);
if (priorityCompare != 0) return priorityCompare;
// If priorities are equal, sort by due date
if (a.due == null && b.due == null) return 0;
if (a.due == null) return 1;
if (b.due == null) return -1;
return a.due!.compareTo(b.due!);
Comment on lines +70 to +84
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This secondary sorting logic by due date is duplicated across multiple files (show_tasks.dart, show_tasks_replica.dart, widget.controller.dart, and comparator.dart). This code duplication makes maintenance harder and increases the risk of inconsistencies. Consider extracting this logic into a reusable helper function that can be shared across all these locations to ensure consistent behavior and easier maintenance.

Copilot uses AI. Check for mistakes.
case 'Project+':
return a.project!.compareTo(b.project!);
case 'Project-':
Expand Down
12 changes: 10 additions & 2 deletions lib/app/modules/home/views/show_tasks_replica.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,17 @@ class TaskReplicaViewBuilder extends StatelessWidget {
case 'Due till-':
return (b.due ?? '').compareTo(a.due ?? '');
case 'Priority+':
return (a.priority ?? '').compareTo(b.priority ?? '');
final priorityCompare =
(a.priority ?? '').compareTo(b.priority ?? '');
if (priorityCompare != 0) return priorityCompare;
// If priorities are equal, sort by due date
return (a.due ?? '').compareTo(b.due ?? '');
case 'Priority-':
return (b.priority ?? '').compareTo(a.priority ?? '');
final priorityCompare =
(b.priority ?? '').compareTo(a.priority ?? '');
if (priorityCompare != 0) return priorityCompare;
// If priorities are equal, sort by due date
return (a.due ?? '').compareTo(b.due ?? '');
Comment on lines +63 to +73
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The secondary sort by due date uses string comparison instead of null-safe DateTime comparison. When 'a.due' or 'b.due' is null, the empty string '' will be compared, which may not produce the intended sorting order. Tasks without due dates should be placed after tasks with due dates, but string comparison of empty strings doesn't guarantee this behavior. Consider using explicit null checks as done in the other files (show_tasks.dart and widget.controller.dart) to ensure consistent sorting behavior.

Copilot uses AI. Check for mistakes.
default:
return 0;
}
Expand Down
13 changes: 12 additions & 1 deletion lib/app/utils/taskfunctions/comparator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:math';
import 'package:taskwarrior/app/models/json/task.dart';
import 'package:taskwarrior/app/utils/taskfunctions/urgency.dart';


int Function(Task, Task) compareTasks(String column) {
return (a, b) {
int? result;
Expand Down Expand Up @@ -48,6 +47,18 @@ int Function(Task, Task) compareTasks(String column) {
var compare = {'H': 2, 'M': 1, 'L': 0};
result =
(compare[a.priority] ?? -1).compareTo(compare[b.priority] ?? -1);
// If priorities are equal, sort by due date
if (result == 0) {
if (a.due == null && b.due == null) {
result = 0;
} else if (a.due == null) {
result = 1;
} else if (b.due == null) {
result = -1;
} else {
result = a.due!.compareTo(b.due!);
}
}
Comment on lines +50 to +61
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new secondary sorting logic for priority (sorting by due date when priorities are equal) lacks test coverage. The existing test for Priority in test/utils/taskfunctions/comparator_test.dart only tests the primary priority comparison and doesn't cover the scenario where two tasks have equal priority. Consider adding test cases that verify tasks with the same priority are correctly sorted by due date, including edge cases where one or both tasks have null due dates.

Copilot uses AI. Check for mistakes.
break;
case 'Project':
result = (a.project ?? '').compareTo(b.project ?? '');
Expand Down