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
- SearchHistoryItem
- Represents a historical search query.
- SearchHistoryItemAdapter
- SearchHistoryRepository
- Repository for managing search history using Hive.
- SearchItem
- Represents a single searchable item in the app.
- SearchItemAdapter
- 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
- Extension on BuildContext for convenient search navigation.
Properties
-
clearSearchCacheProvider
→ AutoDisposeProvider<
void Function()> -
Provider for clearing search cache.
final
-
clearSearchHistoryProvider
→ AutoDisposeProvider<
void Function()> -
Provider for clearing search history.
final
-
recentSearchesProvider
→ AutoDisposeFutureProvider<
List< String> > -
Provider for recent search history.
final
-
searchCacheRepositoryProvider
→ AutoDisposeProvider<
SearchCacheRepository> -
Provider for the search cache repository.
final
-
searchHistoryRepositoryProvider
→ AutoDisposeProvider<
SearchHistoryRepository> -
Provider for the search history repository.
final
-
searchProviderProvider
→ Provider<
SearchProvider> -
Provider for the search provider implementation.
final
-
searchQueryProvider
→ AutoDisposeStateProvider<
String> -
Provider for the current search query.
final
-
searchResultsProvider
→ AutoDisposeFutureProvider<
SearchResult> -
Provider for search results.
final
-
searchSuggestionsProvider
→ AutoDisposeFutureProviderFamily<
List< String> , String> -
Provider for search suggestions.
final
Exceptions / Errors
- CancelledException
- Exception thrown when an operation is cancelled via a CancellationToken.