Future<void> initializeExerciseData() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
if (!prefs.containsKey('exercises_initialized')) {
Map<String, bool> initialData = {
'arithmetic_completed': false,
'arithmetic_addSubOne': false,
'arithmetic_addSubTwo': false,
'arithmetic_addSubThree': false,
};
// Set Data To Shared Prefs
initialData.forEach((key, value) {
prefs.setBool(key, value);
});
// Set Exercise Inıt To Shared Prefs
prefs.setBool('exercises_initialized', true);
}
}
Category Screen (Such as Arithmetic)
Future<void> getExerciseData() async {
final prefs = await SharedPreferences.getInstance();
setState(() {
completionStatus = {
'arithmetic_addSubOne': prefs.getBool('arithmetic_addSubOne') ?? false,
'arithmetic_addSubTwo': prefs.getBool('arithmetic_addSubTwo') ?? false,
'arithmetic_addSubThree':
prefs.getBool('arithmetic_addSubThree') ?? false,
'arithmetic_addSubFour':
prefs.getBool('arithmetic_addSubFour') ?? false,
'arithmetic_addSubFive':
prefs.getBool('arithmetic_addSubFive') ?? false,
};
});
}
@override
void initState() {
super.initState();
// Init Exercise Data With Shared Prefs
getExerciseData();
}
Complete exercise in Practice Screen
Future<void> completeExerciseSharedPrefs(String key) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setBool(key, true);
}
completeExerciseSharedPrefs("arithmetic_addSubOne");
I got some problem with reflecting completed exercise (green mark in image ) in the screen.
The problem is when we go through category screen ( such as arithmetic ) to practice screen like (add sub one) and complete the practice successfully it is registering the add_subone as completed to shared prefs its working as expected.
But when we complete the exercise and go to second complexity via congrats screen (add_subtwo) and pop back to arithmetic ( category screen) completed exercise doesnt marked as completed.
We can only see this completed mark if we pop back to one screen back ( such as home screen ) and revisit the arithmetic.
how can ı solve that ?
3