animalCaptcha method
Implementation
CaptchaResult animalCaptcha({
List<Map>? emojis,
int captchaLength = 5,
Duration timeOut = const Duration(minutes: 1),
}) {
emojis ??= animalEmoji;
if (captchaLength > emojis.length) {
throw "captchaLength melebihi emojis length";
}
Map jsonKey = emojis[Random().nextInt(emojis.length)];
List<Map> result = [jsonKey];
DateTime dateTime = DateTime.now().add(timeOut);
while (true) {
if (dateTime.isBefore(DateTime.now())) {}
if (result.length == captchaLength) {
return CaptchaResult(
answer: jsonKey,
captchas: result,
);
}
Map randomEmoji = emojis[Random().nextInt(emojis.length)];
if (!DeepCollectionEquality().equals(randomEmoji, jsonKey)) {
bool isNotFoundSame = true;
for (var index = 0; index < result.length; index++) {
if (DeepCollectionEquality().equals(randomEmoji, result[index])) {
isNotFoundSame = false;
}
}
if (isNotFoundSame) {
result.add(randomEmoji);
result.shuffle();
}
}
}
}