editTask method
Future<bool> editTask ({required String title, required String description, required String deadline, required String taskId})
This function is used to edit the task created by the user.
params:
title
: task title.description
: task description.deadline
: task deadline.taskId
: task Id.
Implementation
Future<bool> editTask({
required String title,
required String description,
required String deadline,
required String taskId,
}) async {
_databaseMutationFunctions
.refreshAccessToken(_userConfig.currentUser.refreshToken!);
final res = await _databaseMutationFunctions.gqlAuthMutation(
TaskQueries.editTask(
title: title,
description: description,
deadline: deadline,
taskId: taskId,
),
);
// if res is not null.
if (res != null) {
final updatedtaskJson = res.data!['updateTask'] as Map<String, dynamic>;
final index = _tasks.indexWhere((task) => task.id == taskId);
if (index == -1) return false;
final updatedtask = Task.fromJson(updatedtaskJson);
updatedtask.event.title = _tasks[index].event.title;
_tasks[index] = updatedtask;
callbackNotifyListeners();
// if successfully updated then return true.
return true;
}
return false;
}