execute method

Result<Task> execute(
  1. KanbanColumn column,
  2. int index,
  3. String newTitle,
  4. String newSubtitle,
)

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 task
  • index: The index of the task to edit
  • newTitle: The new title for the task
  • newSubtitle: 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()}');
  }
}