Phrase.fromString constructor
Phrase.fromString(
- String phrase
Implementation
factory Phrase.fromString(String phrase) {
final arr = phrase.trim().split(' ');
final invalidWords = <String>[];
for (final word in arr) {
if (!_phraseWordsList.any((e) => e == word)) {
invalidWords.add(word);
}
}
if (invalidWords.isNotEmpty) {
throw PhaseException(message: 'Invalid phrase', wordList: invalidWords);
}
if (arr.length != 12 && arr.length != 24) {
throw PhaseException(
message: 'Invalid phrase length of ${arr.length}, expected 12 or 24.',
);
}
return Phrase(phrase);
}