execute method
Edits an existing task at the specified index in the column.
Notifies listeners with a TaskEditedEvent when successful. Returns a Result containing the updated task.
Parameters:
column: The column containing the taskindex: The index of the task to editnewTitle: The new title for the tasknewSubtitle: The new subtitle for the task
Throws TaskOperationException if the task cannot be edited.
Implementation
Result<Task> execute(KanbanColumn column, int index, String newTitle, String newSubtitle) {
try {
final task = column.tasks[index];
// Check if any changes are needed
if (task.title == newTitle && task.subtitle == newSubtitle) {
return Success(task);
}
final updatedTask = task.copyWith(
title: newTitle,
subtitle: newSubtitle,
);
column.replaceTask(index, updatedTask);
EventNotifier().notify(TaskEditedEvent(task, updatedTask, column));
return Success(updatedTask);
} catch (e) {
throw TaskOperationException('Failed to edit task: ${e.toString()}');
}
}