refactoring

pull/148/head
faizatflutter 3 months ago
parent 57f693e0d9
commit 597579e677

@ -1065,9 +1065,8 @@ class WaterMonitorViewModel extends ChangeNotifier {
notifyListeners(); notifyListeners();
return false; return false;
}, },
(apiModel) { (apiModel) async {
log("Insert user activity success: ${apiModel.data.toString()}"); 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) { if (apiModel.data != null && apiModel.data is List && (apiModel.data as List).isNotEmpty) {
final progressData = (apiModel.data as List).first; final progressData = (apiModel.data as List).first;
if (progressData is Map) { if (progressData is Map) {
@ -1090,7 +1089,7 @@ class WaterMonitorViewModel extends ChangeNotifier {
} }
// Refresh progress data to ensure consistency // Refresh progress data to ensure consistency
fetchUserProgressForMonitoring(); await fetchUserProgressForMonitoring();
} }
_isLoading = false; _isLoading = false;
@ -1140,7 +1139,7 @@ class WaterMonitorViewModel extends ChangeNotifier {
notifyListeners(); notifyListeners();
return false; return false;
}, },
(apiModel) { (apiModel) async {
log("Undo user activity success: ${apiModel.data.toString()}"); log("Undo user activity success: ${apiModel.data.toString()}");
// Update consumed amount and goal from the response // Update consumed amount and goal from the response
@ -1164,8 +1163,8 @@ class WaterMonitorViewModel extends ChangeNotifier {
} }
} }
} }
await fetchUserProgressForMonitoring();
} }
fetchUserProgressForMonitoring();
_isLoading = false; _isLoading = false;
notifyListeners(); notifyListeners();
return true; return true;

@ -18,14 +18,19 @@ class WaterActionButtonsWidget extends StatelessWidget {
return Consumer<WaterMonitorViewModel>(builder: (context, vm, _) { return Consumer<WaterMonitorViewModel>(builder: (context, vm, _) {
final cupAmount = vm.selectedCupCapacityMl; final cupAmount = vm.selectedCupCapacityMl;
final isGoalAchieved = vm.progressPercent >= 100 || vm.nextDrinkTime.toLowerCase().contains('goal achieved'); final isGoalAchieved = vm.progressPercent >= 100 || vm.nextDrinkTime.toLowerCase().contains('goal achieved');
final isDisabled = vm.isLoading || isGoalAchieved;
return Column( return Column(
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
InkWell( Opacity(
onTap: () async { opacity: vm.isLoading ? 0.4 : 1.0,
child: InkWell(
onTap: vm.isLoading
? null
: () async {
if (cupAmount > 0) { if (cupAmount > 0) {
await vm.undoUserActivity(); await vm.undoUserActivity();
} }
@ -37,6 +42,7 @@ class WaterActionButtonsWidget extends StatelessWidget {
iconColor: AppColors.textColor, iconColor: AppColors.textColor,
), ),
), ),
),
Container( Container(
margin: EdgeInsets.symmetric(horizontal: 4.w), margin: EdgeInsets.symmetric(horizontal: 4.w),
padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h), padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h),
@ -51,9 +57,9 @@ class WaterActionButtonsWidget extends StatelessWidget {
), ),
), ),
Opacity( Opacity(
opacity: isGoalAchieved ? 0.4 : 1.0, opacity: isDisabled ? 0.4 : 1.0,
child: InkWell( child: InkWell(
onTap: isGoalAchieved onTap: isDisabled
? null ? null
: () async { : () async {
if (cupAmount > 0) { if (cupAmount > 0) {

Loading…
Cancel
Save