在Flutter中,我们如何在showSearch()小部件的委托中转换searchFieldLabel?

时间:2020-03-03 01:41:46

标签: flutter dart localization internationalization intl

我有以下代码来生成showSearch()小部件

onTap: () {
    showSearch(
        context: context,
        delegate: CustomSearchDelegate(),
        query: '',
    );
},

现在在CustomSearchDelegate中,我在构造器中有以下代码需要翻译。

class CustomSearchDelegate extends SearchDelegate {
    CustomSearchDelegate()
      : super(
          searchFieldLabel: Translations.of(context).searchAnyKeyword,
          keyboardType: TextInputType.text,
          textInputAction: TextInputAction.search,
        );

现在的问题是,我需要context来执行翻译,here

当我们在context函数中使用该委托时,该委托肯定具有build。问题是如何在构造函数中访问它?

0 个答案:

没有答案