So I am working on a fitness app in flutter with firebase. I have this “freestyles” workout data structure where I am storing the exerciseIds of the exercises done in that workout. They’re being stored in an array “exerciseIds” where the indices are the order that I want. However, in my attempt to pull and retrieve that data back into my code, it is ordering it in alphanumerical order (or unicode order).
So when I pull it back into my code, I want it in order of index (0, 1, 2), but it is arranging to 2,1,0 in this case because that is the “unicode order” (0 – 9, A – Z, a – z) of the exercise ids given that value of index 2 starts with 2, index 1 starts with T, and index 0 starts wit o.
How can I retrieve the data in the indexed order?
Here is where I am pulling it back:
void _loadActiveWorkout() async {
if (activeWorkout != null) {
List<Exercise?> exercises = await exerciseDB.fetchById(activeWorkout!.exerciseIds);
setState(() {
exerciseList = exercises;
itemCounter = exercises.length;
setCounter = List.generate(exerciseList.length, (_) => 1);
for (var i = 0; i < exerciseList.length; i++) {
final exerciseId = exerciseList[i]!.id;
for (var exercise in activeWorkout!.exercises) {
if (exercise['exerciseId'] == exerciseId) {
setCounter[i] = exercise['sets'].length + 1;
break;
}
}
}
freestyleId = activeWorkout!.id;
});
}
}
Some of this code may look fairly messy lol (I’m quite beginner level).
I don’t really know how to approach correcting this.