fix: if lemma not in choices list, add instead of replace (#1538)
This commit is contained in:
parent
a638319926
commit
ce57cbfdea
1 changed files with 6 additions and 3 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue