68 lines
2.4 KiB
Dart
68 lines
2.4 KiB
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class QuizPrefs {
|
|
static const String _kSeenQuizKey = 'seen_oral_quiz_v1';
|
|
static const String _kLastScoreKey = 'last_oral_quiz_score_v1';
|
|
static const String _kLastMaxScoreKey = 'last_oral_quiz_max_score_v1';
|
|
|
|
static String _scopeKey(String base, String? scopeId) {
|
|
final id = (scopeId ?? '').trim();
|
|
if (id.isEmpty) return base;
|
|
return '${base}_$id';
|
|
}
|
|
|
|
static Future<bool> hasSeenQuiz() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
return prefs.getBool(_kSeenQuizKey) ?? false;
|
|
}
|
|
|
|
static Future<void> markQuizSeen() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setBool(_kSeenQuizKey, true);
|
|
}
|
|
|
|
static Future<void> saveLastResult({required int score, required int maxScore}) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setInt(_kLastScoreKey, score);
|
|
await prefs.setInt(_kLastMaxScoreKey, maxScore);
|
|
}
|
|
|
|
static Future<void> saveLastResultForUser({required String userId, required int score, required int maxScore}) async {
|
|
await saveLastResultForScope(scopeId: userId, score: score, maxScore: maxScore);
|
|
}
|
|
|
|
static Future<void> saveLastResultForScope({required String scopeId, required int score, required int maxScore}) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setInt(_scopeKey(_kLastScoreKey, scopeId), score);
|
|
await prefs.setInt(_scopeKey(_kLastMaxScoreKey, scopeId), maxScore);
|
|
}
|
|
|
|
static Future<int?> getLastScore() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
return prefs.getInt(_kLastScoreKey);
|
|
}
|
|
|
|
static Future<int?> getLastScoreForUser(String userId) async {
|
|
return getLastScoreForScope(userId);
|
|
}
|
|
|
|
static Future<int?> getLastScoreForScope(String scopeId) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
return prefs.getInt(_scopeKey(_kLastScoreKey, scopeId));
|
|
}
|
|
|
|
static Future<int?> getLastMaxScore() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
return prefs.getInt(_kLastMaxScoreKey);
|
|
}
|
|
|
|
static Future<int?> getLastMaxScoreForUser(String userId) async {
|
|
return getLastMaxScoreForScope(userId);
|
|
}
|
|
|
|
static Future<int?> getLastMaxScoreForScope(String scopeId) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
return prefs.getInt(_scopeKey(_kLastMaxScoreKey, scopeId));
|
|
}
|
|
}
|