扑动:支持的语言正在抛出错误(Localizations.of<MaterialLocalizations>(上下文,MaterialLocalizations)returns null)
flutter: supported language is throwing error (Localizations.of<MaterialLocalizations>(context, MaterialLocalizations) returns null)
每次启动我的应用程序时,我都会在日志中收到以下警告:
════════
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
这样的各种小部件时,或者当试图显示一个对话框时,我不能这样做,因为 flutter 会抛出以下断言(异常):
No MaterialLocalizations found.
因为
Localizations.of<MaterialLocalizations>(context, MaterialLocalizations) == null
断言为真。
德语被列为受支持的语言环境,我在 MaterialApp
中注册了 supportedLanguages
和 localizationDelegates
。因为我使用 MaterialApp
作为主根 StatelessWidget
,我不明白为什么会抛出这个错误。
我已经搜索了,发现的不多,就this old question with no real answer to it, which is the same problem. There is also a GitHub issue这个问题,但好像没有多少人有同样的问题。
对于任何未来 reader,我发现了问题:
我没有包含包裹:
flutter_localizations:
sdk: flutter
并且也不包括 GlobalMaterialLocalization
代表:
localizationsDelegates: [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
每次启动我的应用程序时,我都会在日志中收到以下警告:
════════
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
这样的各种小部件时,或者当试图显示一个对话框时,我不能这样做,因为 flutter 会抛出以下断言(异常):
No MaterialLocalizations found.
因为
Localizations.of<MaterialLocalizations>(context, MaterialLocalizations) == null
断言为真。
德语被列为受支持的语言环境,我在 MaterialApp
中注册了 supportedLanguages
和 localizationDelegates
。因为我使用 MaterialApp
作为主根 StatelessWidget
,我不明白为什么会抛出这个错误。
我已经搜索了,发现的不多,就this old question with no real answer to it, which is the same problem. There is also a GitHub issue这个问题,但好像没有多少人有同样的问题。
对于任何未来 reader,我发现了问题: 我没有包含包裹:
flutter_localizations:
sdk: flutter
并且也不包括 GlobalMaterialLocalization
代表:
localizationsDelegates: [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],