refactoring

faiz_dev
faizatflutter 2 weeks ago
parent 57f693e0d9
commit 597579e677

@ -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;

@ -18,23 +18,29 @@ class WaterActionButtonsWidget extends StatelessWidget {
return Consumer<WaterMonitorViewModel>(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) {

Loading…
Cancel
Save