This widget displays a list of indices,
allowing a user to change the way hits are sorting
(with replica indices).
Another common use case for this widget is to let users switch between different indices.
For this widget to work,
you must define all indices that you pass down as options as replicas of the main .
Examples
class SearchSortBy extends StatefulWidget {
const SearchSortBy({
super.key,
required this.searcher,
required this.sorts,
required this.selected,
});
final HitsSearcher searcher; // can be lifted up (w/ callback)
final Map<String, String> sorts;
final String selected;
@override
State<SearchSortBy> createState() => _SearchSortByState();
}
class _SearchSortByState extends State<SearchSortBy> {
late String selected = widget.selected;
@override
Widget build(BuildContext context) {
return Card(
child: DropdownButton(
value: selected,
items: widget.sorts.keys
.map((sort) => DropdownMenuItem(
value: sort,
child: Text(sort),
))
.toList(),
onChanged: (value) {
setState(() => selected = value!);
widget.searcher.applyState(
(state) => state.copyWith(indexName: widget.sorts[value]!));
},
),
);
}
}
Last modified on March 23, 2026