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

pull/1593/head
ggurdin 10 months ago committed by GitHub
parent a638319926
commit ce57cbfdea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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

Loading…
Cancel
Save