fix: disable other practice choices immeadiatley after correct choice made

This commit is contained in:
ggurdin 2026-01-20 12:56:10 -05:00
parent be9e1f6fac
commit 2b68f4a1fb
No known key found for this signature in database
GPG key ID: A01CB41737CBB478
4 changed files with 41 additions and 20 deletions

View file

@ -83,6 +83,7 @@ class AnalyticsPracticeState extends State<AnalyticsPractice>
ValueNotifier<MessageActivityRequest?>(null);
final ValueNotifier<double> progressNotifier = ValueNotifier<double>(0.0);
final ValueNotifier<bool> enableChoicesNotifier = ValueNotifier<bool>(true);
final Map<String, Map<String, String>> _choiceTexts = {};
final Map<String, Map<String, String?>> _choiceEmojis = {};
@ -106,6 +107,7 @@ class AnalyticsPracticeState extends State<AnalyticsPractice>
activityState.dispose();
activityTarget.dispose();
progressNotifier.dispose();
enableChoicesNotifier.dispose();
super.dispose();
}
@ -190,6 +192,7 @@ class AnalyticsPracticeState extends State<AnalyticsPractice>
void _resetActivityState() {
activityState.value = const AsyncState.loading();
activityTarget.value = null;
enableChoicesNotifier.value = true;
}
void _resetSessionState() {
@ -272,6 +275,7 @@ class AnalyticsPracticeState extends State<AnalyticsPractice>
Future<void> _continueSession() async {
if (_continuing) return;
_continuing = true;
enableChoicesNotifier.value = true;
try {
if (activityState.value
@ -403,6 +407,10 @@ class AnalyticsPracticeState extends State<AnalyticsPractice>
) async {
if (_currentActivity == null) return;
final activity = _currentActivity!;
final isCorrect = activity.multipleChoiceContent.isCorrect(choiceContent);
if (isCorrect) {
enableChoicesNotifier.value = false;
}
// Update activity record
PracticeRecordController.onSelectChoice(

View file

@ -346,25 +346,29 @@ class _ActivityChoicesWidget extends StatelessWidget {
return Container(
constraints: const BoxConstraints(maxHeight: 400.0),
child: Column(
spacing: 4.0,
mainAxisSize: MainAxisSize.min,
children: choices
.map(
(choice) => _ChoiceCard(
activity: value,
targetId:
controller.choiceTargetId(choice.choiceId),
choiceId: choice.choiceId,
onPressed: () => controller.onSelectChoice(
choice.choiceId,
child: ValueListenableBuilder(
valueListenable: controller.enableChoicesNotifier,
builder: (context, enabled, __) => Column(
spacing: 4.0,
mainAxisSize: MainAxisSize.min,
children: choices
.map(
(choice) => _ChoiceCard(
activity: value,
targetId:
controller.choiceTargetId(choice.choiceId),
choiceId: choice.choiceId,
onPressed: () => controller.onSelectChoice(
choice.choiceId,
),
cardHeight: cardHeight,
choiceText: choice.choiceText,
choiceEmoji: choice.choiceEmoji,
enabled: enabled,
),
cardHeight: cardHeight,
choiceText: choice.choiceText,
choiceEmoji: choice.choiceEmoji,
),
)
.toList(),
)
.toList(),
),
),
);
},
@ -390,6 +394,7 @@ class _ChoiceCard extends StatelessWidget {
final String choiceText;
final String? choiceEmoji;
final bool enabled;
const _ChoiceCard({
required this.activity,
@ -399,6 +404,7 @@ class _ChoiceCard extends StatelessWidget {
required this.cardHeight,
required this.choiceText,
required this.choiceEmoji,
this.enabled = true,
});
@override
@ -420,6 +426,7 @@ class _ChoiceCard extends StatelessWidget {
onPressed: onPressed,
isCorrect: isCorrect,
height: cardHeight,
isEnabled: enabled,
);
case ActivityTypeEnum.lemmaAudio:
@ -432,6 +439,7 @@ class _ChoiceCard extends StatelessWidget {
onPressed: onPressed,
isCorrect: isCorrect,
height: cardHeight,
isEnabled: enabled,
);
case ActivityTypeEnum.grammarCategory:
@ -445,6 +453,7 @@ class _ChoiceCard extends StatelessWidget {
tag: choiceText,
onPressed: onPressed,
isCorrect: isCorrect,
enabled: enabled,
);
case ActivityTypeEnum.grammarError:
@ -458,6 +467,7 @@ class _ChoiceCard extends StatelessWidget {
onPressed: onPressed,
isCorrect: isCorrect,
height: cardHeight,
isEnabled: enabled,
child: Text(choiceText),
);
@ -471,6 +481,7 @@ class _ChoiceCard extends StatelessWidget {
onPressed: onPressed,
isCorrect: isCorrect,
height: cardHeight,
isEnabled: enabled,
child: Text(choiceText),
);
}

View file

@ -62,6 +62,7 @@ class _GameChoiceCardState extends State<GameChoiceCard>
Future<void> _handleTap() async {
if (!widget.isEnabled) return;
widget.onPressed();
if (widget.shouldFlip) {
if (_controller.isAnimating || _revealed) return;
@ -73,8 +74,6 @@ class _GameChoiceCardState extends State<GameChoiceCard>
if (_clicked) return;
setState(() => _clicked = true);
}
widget.onPressed();
}
@override

View file

@ -15,6 +15,7 @@ class GrammarChoiceCard extends StatelessWidget {
final VoidCallback onPressed;
final bool isCorrect;
final double height;
final bool enabled;
const GrammarChoiceCard({
required this.choiceId,
@ -24,6 +25,7 @@ class GrammarChoiceCard extends StatelessWidget {
required this.onPressed,
required this.isCorrect,
this.height = 72.0,
this.enabled = true,
super.key,
});
@ -42,6 +44,7 @@ class GrammarChoiceCard extends StatelessWidget {
onPressed: onPressed,
isCorrect: isCorrect,
height: height,
isEnabled: enabled,
child: Text(copy),
);
}