Fix grammar error null error
and only reload current question upon encountering error
This commit is contained in:
parent
cae69a6d34
commit
34ae1f30aa
3 changed files with 34 additions and 10 deletions
|
|
@ -269,6 +269,25 @@ class AnalyticsPracticeState extends State<AnalyticsPractice>
|
|||
await _startSession();
|
||||
}
|
||||
|
||||
Future<void> reloadCurrentActivity() async {
|
||||
if (activityTarget.value == null) return;
|
||||
|
||||
try {
|
||||
activityState.value = const AsyncState.loading();
|
||||
selectedMorphChoice.value = null;
|
||||
|
||||
final req = activityTarget.value!;
|
||||
final res = await _fetchActivity(req);
|
||||
|
||||
if (!mounted) return;
|
||||
activityState.value = AsyncState.loaded(res);
|
||||
_playAudio();
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
activityState.value = AsyncState.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _completeSession() async {
|
||||
_sessionLoader.value!.finishSession();
|
||||
setState(() {});
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class AnalyticsPracticeSessionRepo {
|
|||
AnalyticsActivityTarget(
|
||||
target: PracticeTarget(
|
||||
tokens: [entry.key],
|
||||
activityType: types[targets.length],
|
||||
activityType: ActivityTypeEnum.grammarCategory,
|
||||
morphFeature: entry.value,
|
||||
),
|
||||
),
|
||||
|
|
@ -231,18 +231,23 @@ class AnalyticsPracticeSessionRepo {
|
|||
}
|
||||
|
||||
final choices = igcMatch!.match.choices!.map((c) => c.value).toList();
|
||||
final choiceTokens = tokens.where(
|
||||
(token) =>
|
||||
token.lemma.saveVocab &&
|
||||
choices.any(
|
||||
(choice) => choice.contains(token.text.content),
|
||||
),
|
||||
);
|
||||
final choiceTokens = tokens
|
||||
.where(
|
||||
(token) =>
|
||||
token.lemma.saveVocab &&
|
||||
choices.any(
|
||||
(choice) => choice.contains(token.text.content),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
|
||||
// Skip if no valid tokens found for this grammar error
|
||||
if (choiceTokens.isEmpty) continue;
|
||||
|
||||
targets.add(
|
||||
AnalyticsActivityTarget(
|
||||
target: PracticeTarget(
|
||||
tokens: choiceTokens.toList(),
|
||||
tokens: choiceTokens,
|
||||
activityType: ActivityTypeEnum.grammarError,
|
||||
morphFeature: null,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -329,7 +329,7 @@ class _ActivityChoicesWidget extends StatelessWidget {
|
|||
ErrorIndicator(message: error.toString()),
|
||||
const SizedBox(height: 16),
|
||||
TextButton.icon(
|
||||
onPressed: controller.reloadSession,
|
||||
onPressed: controller.reloadCurrentActivity,
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: Text(L10n.of(context).tryAgain),
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue