findWord method
Finds all occurrences of the given word in the text and highlights them.
The word parameter is a Stirng and it is the word to search for.
The highlightStyle parameter is an optional TextStyle to apply to the highlighted words.
Defaults to
TextStyle(backgroundColor: Colors.amberAccent.withAlpha(80))
Implementation
void findWord(String word, {TextStyle? highlightStyle}) {
_highlightStyle = highlightStyle;
_highlightIndex.clear();
if (word.isNotEmpty) {
final regExp = RegExp('\\b$word\\b');
for (final match in regExp.allMatches(text)) {
_highlightIndex
.putIfAbsent(word.length, () => <int>{})
.add(match.start);
}
}
}