【问题标题】:The getter 'languageCode' isn't defined for the type 'List<Locale>'没有为类型“List<Locale>”定义 getter 'languageCode'
【发布时间】:2021-02-03 02:14:45
【问题描述】:

我需要我的应用程序支持不同的语言。 但是我在使用 languageCode 属性时遇到了问题。 代码是:

  supportedLocales: [
        Locale('en', ''),
        Locale('ar', ''),
      ],
      localeListResolutionCallback: (currentLocale, supportedLocales) {
        if (currentLocale != null) {
          print(currentLocale.languageCode);
          for(Locale locale in supportedLocales){
           // if(currentLocale.languageCode== )
          }
        }
        return supportedLocales.first;
      },

问题是: 没有为类型“列表”定义吸气剂“语言代码”。 尝试导入定义“languageCode”的库,将名称更正为现有 getter 的名称,或定义名为“languageCode”的 getter 或字段。

【问题讨论】:

标签: flutter localization


【解决方案1】:

在您的代码中 currentLocale 是一个数组。您应该定义它的语言环境以获得更正确的名称。你需要像这样使用它:

    localeListResolutionCallback: (locales, supported) {
          locales.forEach((l) => print(l.languageCode));

【讨论】:

    【解决方案2】:

    从“localeListResolutionCallback”中删除“列表”文本。

    【讨论】:

      猜你喜欢
      • 2021-11-22
      • 1970-01-01
      • 2021-07-27
      • 2020-09-02
      • 2021-07-23
      • 2022-10-09
      • 2021-10-19
      • 2021-08-29
      • 2021-05-21
      相关资源
      最近更新 更多