getSuggestions method

  1. @override
Future<List<SearchItem>> getSuggestions(
  1. String query
)
override

Provides search suggestions based on partial input.

Returns a list of suggested search queries or items based on the partial query. This method is called as the user types in the search field to provide real-time suggestions.

The default implementation returns an empty list. Override this method to provide custom suggestion logic.

Implementation

@override
Future<List<SearchItem>> getSuggestions(String query) async {
  if (query.isEmpty) {
    return [];
  }

  final normalizedQuery = query.toLowerCase();
  final suggestions = _indexed
      .where((indexed) {
        return indexed.normalizedTitle.startsWith(normalizedQuery) ||
            indexed.normalizedSubtitle.startsWith(normalizedQuery);
      })
      .map((e) => e.item)
      .take(5)
      .toList();

  return suggestions;
}