I have a logic issue in my flutter app, the user first of all adds his workout, and the for each workout he should add sets. While adding sets there is a placeholder to add weights and reps, so the user can add the desired number of sets.. but the issue is with the removal of the last added set after adding it: clicking “Supprimez un set” removes the set from the list correctly but in the ui it removes the placeholder that should be always shown. I don’t know if I have clearly explained it but here are 2 screenshots to show more:
Before removing the last added set:
After removing the last added set:
It should actually keep the placeholder and delete the last set that is added.. when I log the data it is correctly deleted but in the ui it removes the placeholder.
I appreciate your help
Here is my code:
void _deleteSet(int index) {
setState(() {
int setIndexToRemove = widget.workoutsList[index].workoutSets!.length - 1;
if (setIndexToRemove >= 0) {
widget.workoutsList[index].workoutSets!.removeAt(setIndexToRemove);
for (var item in widget.workoutsList[index].workoutSets!) {
print(item.repetitions);
}
} else {
if (kDebugMode) {
const ErrorDialog(
title: "Oops...", contentText: "Pas de set pour supprimez");
}
}
});
}
And my listView:
ListView.builder(
itemCount: workout.workoutSets!.isEmpty
? 1
: workout.workoutSets!.length + 1,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, setIndex) {
if (setIndex <
workout.workoutSets!.length + 1) {
return WorkoutSetRow(
setIndex: setIndex,
onRepsChanged: (dynamic value) {
repsValue = int.parse(value);
},
onWeightChanged: (dynamic value) {
weightValue = double.parse(value);
},
);
} else {
return Container();
}
},
),