diff --git a/lib/features/water_monitor/water_monitor_view_model.dart b/lib/features/water_monitor/water_monitor_view_model.dart index 01167fe..18ffddd 100644 --- a/lib/features/water_monitor/water_monitor_view_model.dart +++ b/lib/features/water_monitor/water_monitor_view_model.dart @@ -1065,9 +1065,8 @@ class WaterMonitorViewModel extends ChangeNotifier { notifyListeners(); return false; }, - (apiModel) { + (apiModel) async { log("Insert user activity success: ${apiModel.data.toString()}"); - // Update consumed amount and goal from the response if (apiModel.data != null && apiModel.data is List && (apiModel.data as List).isNotEmpty) { final progressData = (apiModel.data as List).first; if (progressData is Map) { @@ -1090,7 +1089,7 @@ class WaterMonitorViewModel extends ChangeNotifier { } // Refresh progress data to ensure consistency - fetchUserProgressForMonitoring(); + await fetchUserProgressForMonitoring(); } _isLoading = false; @@ -1140,7 +1139,7 @@ class WaterMonitorViewModel extends ChangeNotifier { notifyListeners(); return false; }, - (apiModel) { + (apiModel) async { log("Undo user activity success: ${apiModel.data.toString()}"); // Update consumed amount and goal from the response @@ -1164,8 +1163,8 @@ class WaterMonitorViewModel extends ChangeNotifier { } } } + await fetchUserProgressForMonitoring(); } - fetchUserProgressForMonitoring(); _isLoading = false; notifyListeners(); return true; diff --git a/lib/presentation/water_monitor/widgets/water_action_buttons_widget.dart b/lib/presentation/water_monitor/widgets/water_action_buttons_widget.dart index 6546f77..9779562 100644 --- a/lib/presentation/water_monitor/widgets/water_action_buttons_widget.dart +++ b/lib/presentation/water_monitor/widgets/water_action_buttons_widget.dart @@ -18,23 +18,29 @@ class WaterActionButtonsWidget extends StatelessWidget { return Consumer(builder: (context, vm, _) { final cupAmount = vm.selectedCupCapacityMl; final isGoalAchieved = vm.progressPercent >= 100 || vm.nextDrinkTime.toLowerCase().contains('goal achieved'); + final isDisabled = vm.isLoading || isGoalAchieved; return Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - InkWell( - onTap: () async { - if (cupAmount > 0) { - await vm.undoUserActivity(); - } - }, - child: Utils.buildSvgWithAssets( - icon: AppAssets.minimizeIcon, - height: 20.h, - width: 20.h, - iconColor: AppColors.textColor, + Opacity( + opacity: vm.isLoading ? 0.4 : 1.0, + child: InkWell( + onTap: vm.isLoading + ? null + : () async { + if (cupAmount > 0) { + await vm.undoUserActivity(); + } + }, + child: Utils.buildSvgWithAssets( + icon: AppAssets.minimizeIcon, + height: 20.h, + width: 20.h, + iconColor: AppColors.textColor, + ), ), ), Container( @@ -51,9 +57,9 @@ class WaterActionButtonsWidget extends StatelessWidget { ), ), Opacity( - opacity: isGoalAchieved ? 0.4 : 1.0, + opacity: isDisabled ? 0.4 : 1.0, child: InkWell( - onTap: isGoalAchieved + onTap: isDisabled ? null : () async { if (cupAmount > 0) {