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]!));
},
),
);
}
}