app_wide_search library

A high-performance Flutter package for app-wide search with grouped results.

This library provides a complete search solution with:

  • Customizable SearchDelegate and full-screen search interfaces
  • Grouped results with ExpansionTile widgets
  • Offline caching and search history with Hive
  • State management with Riverpod
  • Deep-link support with go_router
  • Internationalization with intl

Usage

First, initialize Hive and register adapters:

import 'package:hive_flutter/hive_flutter.dart';
import 'package:app_wide_search/app_wide_search.dart';

void main() async {
  await Hive.initFlutter();
  Hive.registerAdapter(SearchItemAdapter());
  Hive.registerAdapter(SearchGroupAdapter());
  Hive.registerAdapter(SearchHistoryItemAdapter());
  runApp(const MyApp());
}

Then, provide your search implementation:

ProviderScope(
  overrides: [
    searchProviderProvider.overrideWithValue(
      InMemorySearchProvider(mySearchableItems),
    ),
  ],
  child: MyApp(),
)

Show the search interface:

// Using SearchDelegate
final result = await showSearch(
  context: context,
  delegate: AppWideSearchDelegate(ref: ref),
);

// Or navigate to full-screen search
context.goToSearch();

Classes

AppWideSearchDelegate
A customizable search delegate that integrates with Riverpod.
CancellationToken
A token that can be used to cancel asynchronous operations.
GroupedSearchResults
Displays search results grouped by category using ExpansionTiles.
InMemorySearchProvider
A simple in-memory search provider for testing and examples.
SearchCacheRepository
Repository for caching search results using Hive.
SearchGroup
Represents a group or category of search items.
SearchGroupAdapter
Hive TypeAdapter for SearchGroup. Serializes and deserializes groups for efficient offline caching and fast warm starts.
SearchHistoryItem
Represents a historical search query.
SearchHistoryItemAdapter
Hive TypeAdapter for SearchHistoryItem. Persists recent queries so they can be surfaced instantly on subsequent launches.
SearchHistoryRepository
Repository for managing search history using Hive.
SearchItem
Represents a single searchable item in the app.
SearchItemAdapter
Hive TypeAdapter for SearchItem. Stores searchable entries for in-app providers and offline caches.
SearchLocalizations
Provides localized strings for the search package.
SearchLocalizationsDelegate
Delegate for loading search localizations.
SearchProvider
Contract for implementing custom search backends.
SearchResult
Represents the complete result set from a search operation.
SearchResultList
Displays search results in a list format.
SearchRouteConfig
Configuration for search routes with go_router.
SearchScreen
A full-screen search interface.

Extensions

SearchNavigation on BuildContext
Extension on BuildContext for convenient search navigation.

Properties

clearSearchCacheProvider Provider<void Function()>
Provider for clearing search cache.
final
clearSearchHistoryProvider Provider<void Function()>
Provider for clearing search history.
final
recentSearchesProvider FutureProvider<List<String>>
Provider for recent search history.
final
searchCacheRepositoryProvider Provider<SearchCacheRepository>
Provider for the search cache repository.
final
searchHistoryRepositoryProvider Provider<SearchHistoryRepository>
Provider for the search history repository.
final
searchProviderProvider Provider<SearchProvider>
Provider for the search provider implementation.
final
searchQueryProvider StateProvider<String>
Provider for the current search query.
final
searchResultsProvider FutureProvider<SearchResult>
Provider for search results.
final
searchSuggestionsProvider FutureProviderFamily<List<String>, String>
Provider for search suggestions.
final

Exceptions / Errors

CancelledException
Exception thrown when an operation is cancelled via a CancellationToken.