improvements in editing questions

This commit is contained in:
gitea
2026-02-01 22:21:17 +01:00
parent f3f44c8c69
commit 1ae9413c71
5 changed files with 227 additions and 65 deletions
@@ -80,29 +80,32 @@ class AttemptService {
.firstOrNull ?? questionInAttempt;
final userAnswer = answers[currentQuestion.id];
if (userAnswer == null) {
// Question not answered, treat as incorrect
continue;
}
// Handle both single answer (int) and multiple answers (List<int>)
// Not answering or invalid format: treat same as incorrect
final List<int> userAnswerIndices;
if (userAnswer is int) {
final bool isCorrect;
if (userAnswer == null) {
userAnswerIndices = [];
isCorrect = false;
} else if (userAnswer is int) {
userAnswerIndices = [userAnswer];
final correctIndices = currentQuestion.correctIndices;
final userSet = userAnswerIndices.toSet();
final correctSet = correctIndices.toSet();
isCorrect = userSet.length == correctSet.length &&
userSet.every((idx) => correctSet.contains(idx));
} else if (userAnswer is List<int>) {
userAnswerIndices = userAnswer;
final correctIndices = currentQuestion.correctIndices;
final userSet = userAnswerIndices.toSet();
final correctSet = correctIndices.toSet();
isCorrect = userSet.length == correctSet.length &&
userSet.every((idx) => correctSet.contains(idx));
} else {
// Invalid format, treat as incorrect
continue;
userAnswerIndices = [];
isCorrect = false;
}
// Check if answer is correct
// For multiple correct answers: user must select all correct answers and no incorrect ones
final correctIndices = currentQuestion.correctIndices;
final userSet = userAnswerIndices.toSet();
final correctSet = correctIndices.toSet();
final isCorrect = userSet.length == correctSet.length &&
userSet.every((idx) => correctSet.contains(idx));
final userMarkedNeedsPractice = overrides[currentQuestion.id] ?? false;
// Determine status change (from current deck state)