display grammar copy

This commit is contained in:
ggurdin 2026-01-15 10:36:31 -05:00
parent 326e5c3241
commit 45c31afc2b
No known key found for this signature in database
GPG key ID: A01CB41737CBB478
6 changed files with 81 additions and 8 deletions

View file

@ -163,6 +163,9 @@ class AnalyticsPracticeState extends State<AnalyticsPractice>
}
String getChoiceText(PracticeTarget target, String choiceId) {
if (widget.type == ConstructTypeEnum.morph) {
return choiceId;
}
if (_choiceTexts.containsKey(target) &&
_choiceTexts[target]!.containsKey(choiceId)) {
return _choiceTexts[target]![choiceId]!;
@ -171,8 +174,10 @@ class AnalyticsPracticeState extends State<AnalyticsPractice>
return cId?.lemma ?? choiceId;
}
String? getChoiceEmoji(PracticeTarget target, String choiceId) =>
_choiceEmojis[target]?[choiceId];
String? getChoiceEmoji(PracticeTarget target, String choiceId) {
if (widget.type == ConstructTypeEnum.morph) return null;
return _choiceEmojis[target]?[choiceId];
}
String choiceTargetId(String choiceId) =>
'${widget.type.name}-choice-card-${choiceId.replaceAll(' ', '_')}';

View file

@ -132,6 +132,7 @@ class AnalyticsPracticeSessionRepo {
break;
}
if (use.lemma.isEmpty) continue;
final form = use.form;
if (seenForms.contains(form) || form == null) {
continue;

View file

@ -6,6 +6,7 @@ import 'package:fluffychat/pangea/analytics_practice/analytics_practice_page.dar
import 'package:fluffychat/pangea/analytics_practice/analytics_practice_session_model.dart';
import 'package:fluffychat/pangea/analytics_practice/choice_cards/audio_choice_card.dart';
import 'package:fluffychat/pangea/analytics_practice/choice_cards/game_choice_card.dart';
import 'package:fluffychat/pangea/analytics_practice/choice_cards/grammar_choice_card.dart';
import 'package:fluffychat/pangea/analytics_practice/choice_cards/meaning_choice_card.dart';
import 'package:fluffychat/pangea/analytics_practice/completed_activity_session_view.dart';
import 'package:fluffychat/pangea/analytics_practice/practice_timer_widget.dart';
@ -122,7 +123,7 @@ class _AnalyticsActivityView extends StatelessWidget {
valueListenable: controller.activityTarget,
builder: (context, target, __) => target != null
? Text(
target.promptText(),
target.promptText(context),
textAlign: TextAlign.center,
style:
Theme.of(context).textTheme.titleLarge?.copyWith(
@ -335,6 +336,19 @@ class _ChoiceCard extends StatelessWidget {
height: cardHeight,
);
case ActivityTypeEnum.grammarCategory:
return GrammarChoiceCard(
key: ValueKey(
'${constructId.string}_${activityType.name}_grammar_$choiceId',
),
choiceId: choiceId,
targetId: targetId,
feature: (activity as MorphPracticeActivityModel).morphFeature,
tag: choiceText,
onPressed: onPressed,
isCorrect: isCorrect,
);
default:
return GameChoiceCard(
key: ValueKey(

View file

@ -0,0 +1,48 @@
import 'package:flutter/material.dart';
import 'package:fluffychat/pangea/analytics_practice/choice_cards/game_choice_card.dart';
import 'package:fluffychat/pangea/morphs/get_grammar_copy.dart';
import 'package:fluffychat/pangea/morphs/morph_features_enum.dart';
/// Choice card for meaning activity with emoji, and alt text on flip
class GrammarChoiceCard extends StatelessWidget {
final String choiceId;
final String targetId;
final MorphFeaturesEnum feature;
final String tag;
final VoidCallback onPressed;
final bool isCorrect;
final double height;
const GrammarChoiceCard({
required this.choiceId,
required this.targetId,
required this.feature,
required this.tag,
required this.onPressed,
required this.isCorrect,
this.height = 72.0,
super.key,
});
@override
Widget build(BuildContext context) {
final copy = getGrammarCopy(
category: feature.name,
lemma: tag,
context: context,
) ??
tag;
return GameChoiceCard(
shouldFlip: false,
targetId: targetId,
onPressed: onPressed,
isCorrect: isCorrect,
height: height,
child: Text(copy),
);
}
}

View file

@ -45,9 +45,9 @@ class MorphCategoryActivityGenerator {
)
.toList();
possibleDistractors.shuffle();
final choices = possibleDistractors.take(3).toSet();
final choices = possibleDistractors.take(3).toList();
choices.add(morphTag);
choices.shuffle();
return MessageActivityResponse(
activity: MorphCategoryPracticeActivityModel(
@ -55,7 +55,7 @@ class MorphCategoryActivityGenerator {
langCode: req.userL2,
morphFeature: feature,
multipleChoiceContent: MultipleChoiceActivity(
choices: choices,
choices: choices.toSet(),
answers: {morphTag},
),
),

View file

@ -1,9 +1,11 @@
import 'dart:developer';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:collection/collection.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
import 'package:fluffychat/pangea/constructs/construct_identifier.dart';
import 'package:fluffychat/pangea/events/models/pangea_token_model.dart';
@ -165,10 +167,13 @@ class PracticeTarget {
return false;
}
String promptText() {
String promptText(BuildContext context) {
switch (activityType) {
case ActivityTypeEnum.grammarCategory:
return "${tokens.first.vocabConstructID.lemma}: ${morphFeature!.name}";
return L10n.of(context).whatIsTheMorphTag(
morphFeature!.getDisplayCopy(context),
tokens.first.text.content,
);
default:
return tokens.first.vocabConstructID.lemma;
}