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,23 +18,29 @@ 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,
if (cupAmount > 0) { child: InkWell(
await vm.undoUserActivity(); onTap: vm.isLoading
} ? null
}, : () async {
child: Utils.buildSvgWithAssets( if (cupAmount > 0) {
icon: AppAssets.minimizeIcon, await vm.undoUserActivity();
height: 20.h, }
width: 20.h, },
iconColor: AppColors.textColor, child: Utils.buildSvgWithAssets(
icon: AppAssets.minimizeIcon,
height: 20.h,
width: 20.h,
iconColor: AppColors.textColor,
),
), ),
), ),
Container( Container(
@ -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