This commit is contained in:
Ashwin 2025-12-21 01:34:11 +05:30
parent 1612a05ecc
commit 62fb884c36
3 changed files with 61 additions and 21 deletions

View file

@ -187,7 +187,14 @@ class TasksNotifier extends StateNotifier<TasksState> {
final response = await _apiService.get(url);
if (response.success && response.data != null) {
return Task.fromJson(response.data!);
// API returns { "task_obj": {...}, "attachments": [...], ... }
final taskData = response.data!['task_obj'] as Map<String, dynamic>?;
if (taskData != null) {
debugPrint('TasksNotifier: Task data keys: ${taskData.keys.toList()}');
return Task.fromJson(taskData);
}
debugPrint('TasksNotifier: task_obj not found in response');
return null;
} else {
debugPrint('TasksNotifier: Failed to get task - ${response.message}');
return null;
@ -278,7 +285,34 @@ class TasksNotifier extends StateNotifier<TasksState> {
/// Toggle task completion status
Future<ApiResponse<Map<String, dynamic>>> toggleTaskStatus(Task task) async {
final newStatus = task.completed ? 'New' : 'Completed';
return updateTask(task.id, {'status': newStatus});
return patchTask(task.id, {'status': newStatus});
}
/// Partially update a task (PATCH)
Future<ApiResponse<Map<String, dynamic>>> patchTask(String taskId, Map<String, dynamic> data) async {
try {
final url = '${ApiConfig.tasks}$taskId/';
debugPrint('TasksNotifier: Patching task $taskId with $data');
final response = await _apiService.patch(url, data);
if (response.success && response.data != null) {
// Update the task in local state
final updatedTask = Task.fromJson(response.data!);
state = state.copyWith(
tasks: state.tasks.map((t) => t.id == taskId ? updatedTask : t).toList(),
);
}
return response;
} catch (e) {
debugPrint('TasksNotifier: Exception patching task - $e');
return ApiResponse(
success: false,
message: e.toString(),
statusCode: 0,
);
}
}
}

View file

@ -205,10 +205,12 @@ class _TaskDetailScreenState extends ConsumerState<TaskDetailScreen> {
),
),
child: SafeArea(
bottom: false,
child: Padding(
padding: const EdgeInsets.fromLTRB(24, 60, 24, 24),
padding: const EdgeInsets.fromLTRB(24, 16, 24, 16),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Status Badge
@ -222,10 +224,10 @@ class _TaskDetailScreenState extends ConsumerState<TaskDetailScreen> {
const SizedBox(height: 12),
// Title
// Title - always show
Text(
_task!.title,
style: AppTypography.h1.copyWith(
style: AppTypography.h2.copyWith(
color: AppColors.textPrimary,
decoration: _task!.completed
? TextDecoration.lineThrough

View file

@ -475,23 +475,27 @@ class _TaskFormScreenState extends ConsumerState<TaskFormScreen> {
width: isSelected ? 2 : 1,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
icon,
size: 16,
color: isSelected ? priority.color : AppColors.gray500,
),
const SizedBox(width: 6),
Text(
priority.label,
style: AppTypography.label.copyWith(
color: isSelected ? priority.color : AppColors.textSecondary,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
child: FittedBox(
fit: BoxFit.scaleDown,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Icon(
icon,
size: 16,
color: isSelected ? priority.color : AppColors.gray500,
),
),
],
const SizedBox(width: 6),
Text(
priority.label,
style: AppTypography.label.copyWith(
color: isSelected ? priority.color : AppColors.textSecondary,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
),
),
],
),
),
),
),