From 62fb884c36904870bd28c2995f71bfb6907ffbf2 Mon Sep 17 00:00:00 2001 From: Ashwin Date: Sun, 21 Dec 2025 01:34:11 +0530 Subject: [PATCH] m11 --- mobile/lib/providers/tasks_provider.dart | 38 ++++++++++++++++++- .../lib/screens/tasks/task_detail_screen.dart | 8 ++-- .../lib/screens/tasks/task_form_screen.dart | 36 ++++++++++-------- 3 files changed, 61 insertions(+), 21 deletions(-) diff --git a/mobile/lib/providers/tasks_provider.dart b/mobile/lib/providers/tasks_provider.dart index a22c6987..fdaeca12 100644 --- a/mobile/lib/providers/tasks_provider.dart +++ b/mobile/lib/providers/tasks_provider.dart @@ -187,7 +187,14 @@ class TasksNotifier extends StateNotifier { 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?; + 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 { /// Toggle task completion status Future>> 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>> patchTask(String taskId, Map 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, + ); + } } } diff --git a/mobile/lib/screens/tasks/task_detail_screen.dart b/mobile/lib/screens/tasks/task_detail_screen.dart index 8b73947e..7665117a 100644 --- a/mobile/lib/screens/tasks/task_detail_screen.dart +++ b/mobile/lib/screens/tasks/task_detail_screen.dart @@ -205,10 +205,12 @@ class _TaskDetailScreenState extends ConsumerState { ), ), 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 { 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 diff --git a/mobile/lib/screens/tasks/task_form_screen.dart b/mobile/lib/screens/tasks/task_form_screen.dart index 87a7b105..0dab63f9 100644 --- a/mobile/lib/screens/tasks/task_form_screen.dart +++ b/mobile/lib/screens/tasks/task_form_screen.dart @@ -475,23 +475,27 @@ class _TaskFormScreenState extends ConsumerState { 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, + ), + ), + ], + ), ), ), ),