I have the following code to generate a showSearch()
widget
onTap: () {
showSearch(
context: context,
delegate: CustomSearchDelegate(),
query: '',
);
},
Now in the CustomSearchDelegate
I have the following code in the contructor which needs to be translated.
class CustomSearchDelegate extends SearchDelegate {
CustomSearchDelegate()
: super(
searchFieldLabel: Translations.of(context).searchAnyKeyword,
keyboardType: TextInputType.text,
textInputAction: TextInputAction.search,
);
Now the issue is that I need the context
to perform translations as it is mentioned here
The delegate definitely has the context
as we use it in the build
functions. The question is how to access it in the constructor?