Skip to content

Commit bf3b945

Browse files
committed
Enables user to adjust task assignment weighting
Allows users to influence the automatic task assignment process by setting a weight between due date and priority. This gives the user more control over how tasks are scheduled.
1 parent 091c849 commit bf3b945

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

lib/pages/edit_schedule.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ class _EditScheduleState extends State<EditSchedulePage> {
151151

152152

153153
Future<void> _autoAssign() async {
154-
final confirmed = await AssignTasksDialog.show(context);
155-
if (confirmed == true) {
154+
final double? ratio = await AssignTasksDialog.show(context);
155+
if (ratio != null) {
156156
try {
157-
await autoAssignStudyTime(_weekStart);
157+
await autoAssignStudyTime(_weekStart, ratio);
158158
} catch (e) {
159159
await showDialog(
160160
context: context,

lib/pieces/auto_assign.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import '../database/tasks/get_tasks.dart';
55
import '../database/events/add_events.dart';
66

77
/// Adjust this to balance due date vs priority (1 = only priority, 10 = only due date)
8-
double dueDateWeight = 5.0; // 1-10, can be set from UI
98
109
/// Automatically assigns study_time events to tasks based on priority and due date.
1110
/// Splits events if needed to fit required time and due dates.
1211
/// Call this function and then reload your week/events.
13-
Future<void> autoAssignStudyTime(DateTime weekStart) async {
12+
Future<void> autoAssignStudyTime(DateTime weekStart, double dueDateWeight) async {
1413
// Get all events from today onwards (not just the week)
1514
final now = DateTime.now();
1615
final events = await getAllEvents();

lib/widgets/tasks/assigntasks.dart

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,53 @@ import 'package:fluent_ui/fluent_ui.dart';
33
class AssignTasksDialog {
44
/// Pops up a dialog asking the user to confirm removal.
55
/// Returns true if “Remove” was pressed, false if “Cancel” (or null if dismissed).
6-
static Future<bool?> show(BuildContext context) {
7-
return showDialog<bool>(
6+
static Future<double?> show(BuildContext context) {
7+
double dueDateWeight = 5.0;
8+
return showDialog<double>(
89
context: context,
9-
builder: (ctx) => ContentDialog(
10-
title: const Text('Assign Tasks?'),
11-
content: Text('Are you sure you want to Assign Tasks?'),
12-
actions: [
13-
Button(
14-
child: const Text('Cancel'),
15-
onPressed: () => Navigator.pop(ctx, false),
10+
builder: (_) {
11+
return StatefulBuilder(
12+
builder: (ctx, dialogSetState) => ContentDialog(
13+
title: const Text('Assign Tasks?'),
14+
content: IntrinsicHeight(
15+
child: Column(children: [
16+
Text('Are you sure you want to Assign Tasks?'),
17+
const SizedBox(height: 12),
18+
Text("Duedate weight compared to priority weight"),
19+
const SizedBox(height: 4),
20+
Row(
21+
crossAxisAlignment: CrossAxisAlignment.center,
22+
children: [
23+
const Text("🚨"),
24+
Expanded(
25+
child: Slider(
26+
label: dueDateWeight.toString(),
27+
value: dueDateWeight.toDouble(),
28+
min: 1.0,
29+
max: 10.0,
30+
divisions: 9,
31+
onChanged: (v) =>
32+
dialogSetState(() => dueDateWeight = v.toDouble()),
33+
),
34+
),
35+
const Text("📆"),
36+
],
37+
),
38+
]),
39+
),
40+
actions: [
41+
Button(
42+
child: const Text('Cancel'),
43+
onPressed: () => Navigator.pop(ctx, null),
44+
),
45+
FilledButton(
46+
child: const Text('Assign'),
47+
onPressed: () => Navigator.pop(ctx, dueDateWeight),
48+
),
49+
],
1650
),
17-
FilledButton(
18-
child: const Text('Assign'),
19-
onPressed: () => Navigator.pop(ctx, true),
20-
),
21-
],
22-
),
51+
);
52+
},
2353
);
2454
}
2555
}

0 commit comments

Comments
 (0)