findCompletion method
Finds and sets the current completion based on the current text and available suggestions.
This method should be overridden to customize the completion logic. It should never call notifyListeners.
The default implementation performs a case-insensitive prefix match against the suggestions. If a match is found, current is set with the completion text and full replacement. If no match is found or text is empty, current is set to null to disable typeahead.
Implementation
@visibleForOverriding
@visibleForTesting
void findCompletion([String? text]) {
text ??= this.text;
if (text.isEmpty) {
current = null;
return;
}
for (final suggestion in _suggestions) {
if (suggestion.toLowerCase().startsWith(text.toLowerCase())) {
current = (completion: suggestion.substring(text.length), replacement: suggestion);
return;
}
}
current = null;
}