fix: if lemma not in choices list, add instead of replace (#1538)

This commit is contained in:
ggurdin 2025-01-22 16:00:49 -05:00 committed by GitHub
parent a638319926
commit ce57cbfdea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,4 @@
import 'dart:developer';
import 'dart:math';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
@ -62,9 +61,13 @@ class LemmaActivityGenerator {
// Take the shortest 4
final choices = sortedLemmas.take(4).toList();
if (choices.isEmpty) {
return [token.lemma.text];
}
if (!choices.contains(token.lemma.text)) {
final random = Random();
choices[random.nextInt(choices.length - 1)] = token.lemma.text;
choices.add(token.lemma.text);
choices.shuffle();
}
return choices;
}