繁体   English   中英

flutter (Dart) 方法 'tr' 在 null 处调用

[英]flutter (Dart) Method 'tr' Called at null

我得到了这个 Flutter 应用程序可以使用两种语言。 在菜单中很好地显示项目但是当我尝试编辑并路由到编辑页面时出现此错误(我在同一页面路由中使用添加和编辑但参数不同)当我尝试添加路由时运行良好,没有任何错误但是当我尝试编辑应用程序时,开始在控制台和(在 null 处调用的方法)给我很多错误,并指向我想要本地化的字符串文本。 我使用了 EasyLocalization 小部件。

这里的错误和代码:

@override
Widget build(BuildContext context) {
    var data = EasyLocalizationProvider.of(context).data;
    return EasyLocalizationProvider (
        data: data,
        child: Scaffold (
            appBar: AppBar (
            title: Text(AppLocalizations.of(context).tr("Scan By Trip ID")),
            centerTitle: true,
        ),

这里的错误:

_EmployeeScreenState#a9074):
I/flutter (10733): The method 'tr' was called on null.
I/flutter (10733): Receiver: null
I/flutter (10733): Tried calling: tr("Scan By Trip ID")

您需要将此添加到您的材料应用程序中:

MaterialApp(
 localizationsDelegates: [
   // ... app-specific localization delegate[s] here
   GlobalMaterialLocalizations.delegate,
   GlobalWidgetsLocalizations.delegate,
   GlobalCupertinoLocalizations.delegate,
 ],
 supportedLocales: [
    const Locale('en'), // English
    const Locale('he'), // Hebrew
    const Locale.fromSubtags(languageCode: 'zh'), // Chinese *See Advanced Locales below*
    // ... other locales the app supports
  ],
  // ...
) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM