buildActions method
Widgets to display after the search query in the AppBar.
If the query is not empty, this should typically contain a button to clear the query and show the suggestions again (via showSuggestions) if the results are currently shown.
Returns null if no widget should be shown.
See also:
- AppBar.actions, the intended use for the return value of this method.
Implementation
@override
List<Widget> buildActions(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (this.aggregationField != null) {
debugPrint(
'Warning(SearchBox): The `aggregationField` prop has been marked as deprecated, please use the `distinctField` prop instead.');
}
});
return [
...customActions != null ? customActions! : [],
speechToTextInstance != null
? _MicButton(speechToTextInstance, micOptions: micOptions,
onStart: () {
query = "";
}, onMicResults: (String output) {
if (output != "") {
SearchController? component =
SearchBaseProvider.of(context).getSearchWidget(id);
// clear value
if (component != null) {
component.setValue(output,
options: Options(
triggerCustomQuery: true,
triggerDefaultQuery: true,
stateChanges: false));
query = output;
Future.delayed(Duration(milliseconds: 700)).then((value) {
close(context, null);
});
}
}
})
: Container(),
IconButton(
icon: Icon(Icons.clear),
onPressed: () {
SearchController? component =
SearchBaseProvider.of(context).getSearchWidget(id);
// clear value
if (component != null) {
component.setValue('',
options: Options(
triggerCustomQuery: true, triggerDefaultQuery: true));
}
query = '';
}),
];
}