【问题标题】:flutter: supported language is throwing error (Localizations.of<MaterialLocalizations>(context, MaterialLocalizations) returns null)颤振:支持的语言抛出错误(Localizations.of<MaterialLocalizations>(context, MaterialLocalizations) 返回 null)
【发布时间】:2021-02-25 13:40:58
【问题描述】:

每次启动我的应用程序时,我都会在日志中收到以下警告:

════════
I/flutter (22601): Warning: This application's locale, de, is not supported by all of its
I/flutter (22601): localization delegates.
I/flutter (22601): > A MaterialLocalizations delegate that supports the de locale was not found.
I/flutter (22601): See flutter.dev/tutorials/internationalization for more
I/flutter (22601): information about configuring an app's locale, supportedLocales,
I/flutter (22601): and localizationsDelegates parameters.
I/flutter (22601):
════════

此外,当尝试使用各种小部件(如AppBar)或尝试显示对话框时,我无法这样做,因为颤振会引发以下断言(异常):

No MaterialLocalizations found.

因为

Localizations.of<MaterialLocalizations>(context, MaterialLocalizations) == null

断言为真。

德语被列为受支持的语言环境,我在我的MaterialApp 中注册了supportedLanguageslocalizationDelegates。因为我使用MaterialApp 作为主根StatelessWidget,所以我不明白为什么会抛出这个错误。 我已经搜索并发现不多,只是this old question没有真正的答案,这是同样的问题。这个问题还有一个GitHub issue,但似乎没有多少其他人有同样的问题。

【问题讨论】:

    标签: flutter dart localization flutter-widget


    【解决方案1】:

    对于任何未来的读者,我发现了这个问题: 我没有包含包裹:

    flutter_localizations:
      sdk: flutter
    

    也不包括GlobalMaterialLocalization 代表:

    localizationsDelegates: [
            S.delegate,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
          ],
    

    【讨论】:

      猜你喜欢
      • 2019-04-27
      • 2021-03-15
      • 2021-03-27
      • 1970-01-01
      • 1970-01-01
      • 2019-05-30
      • 1970-01-01
      • 2022-06-18
      • 1970-01-01
      相关资源
      最近更新 更多