This commit is contained in:
gitea
2026-02-01 00:16:24 +01:00
parent 6b8cf10e3c
commit 10a4837ee0
10 changed files with 349 additions and 26 deletions
@@ -25,6 +25,20 @@ class DeckService {
return deck.copyWith(questions: updatedQuestions);
}
/// Toggles the flagged state of a question.
static Deck toggleQuestionFlag({
required Deck deck,
required String questionId,
}) {
final updatedQuestions = deck.questions.map((q) {
if (q.id == questionId) {
return q.copyWith(isFlagged: !q.isFlagged);
}
return q;
}).toList();
return deck.copyWith(questions: updatedQuestions);
}
/// Marks a question as needs practice (manual override).
///
/// Sets isKnown to false and streak to 0, but keeps priority unchanged.
@@ -70,6 +70,12 @@ class Deck {
/// Number of questions marked as known.
int get knownCount => questions.where((q) => q.isKnown).length;
/// Number of questions the user has flagged.
int get flaggedCount => questions.where((q) => q.isFlagged).length;
/// Questions that the user has flagged.
List<Question> get flaggedQuestions => questions.where((q) => q.isFlagged).toList();
/// Practice percentage: (known / total) * 100
double get practicePercentage {
if (questions.isEmpty) return 0.0;
@@ -24,6 +24,9 @@ class Question {
/// Whether this question is considered "known".
final bool isKnown;
/// Whether the user has flagged this question for review.
final bool isFlagged;
/// Priority points (higher = more likely to be selected).
final int priorityPoints;
@@ -44,6 +47,7 @@ class Question {
@Deprecated('Use correctAnswerIndices instead') int? correctAnswerIndex,
this.consecutiveCorrect = 0,
this.isKnown = false,
this.isFlagged = false,
this.priorityPoints = 0,
this.lastAttemptIndex = -1,
this.totalCorrectAttempts = 0,
@@ -61,6 +65,7 @@ class Question {
@Deprecated('Use correctAnswerIndices instead') int? correctAnswerIndex,
int? consecutiveCorrect,
bool? isKnown,
bool? isFlagged,
int? priorityPoints,
int? lastAttemptIndex,
int? totalCorrectAttempts,
@@ -74,6 +79,7 @@ class Question {
correctAnswerIndex: correctAnswerIndex ?? this.correctAnswerIndex,
consecutiveCorrect: consecutiveCorrect ?? this.consecutiveCorrect,
isKnown: isKnown ?? this.isKnown,
isFlagged: isFlagged ?? this.isFlagged,
priorityPoints: priorityPoints ?? this.priorityPoints,
lastAttemptIndex: lastAttemptIndex ?? this.lastAttemptIndex,
totalCorrectAttempts: totalCorrectAttempts ?? this.totalCorrectAttempts,
@@ -117,6 +123,7 @@ class Question {
correctAnswerIndices.toString() == other.correctAnswerIndices.toString() &&
consecutiveCorrect == other.consecutiveCorrect &&
isKnown == other.isKnown &&
isFlagged == other.isFlagged &&
priorityPoints == other.priorityPoints &&
lastAttemptIndex == other.lastAttemptIndex &&
totalCorrectAttempts == other.totalCorrectAttempts &&
@@ -130,6 +137,7 @@ class Question {
correctAnswerIndices.hashCode ^
consecutiveCorrect.hashCode ^
isKnown.hashCode ^
isFlagged.hashCode ^
priorityPoints.hashCode ^
lastAttemptIndex.hashCode ^
totalCorrectAttempts.hashCode ^