简体   繁体   English

如何翻译 Flutter 中的 CheckboxListTile?

[英]How can I translate a CheckboxListTile in Flutter?

This is my code:这是我的代码:

CheckboxListTile (
                  value: agree,
                  title: Text (AppLocalizations.of(context).translate('Do you accept the terms and conditions?'),
                  style: TextStyle(fontSize: 18)),
                  onChanged: (bool value) {
                    setState(() {
                      this.agree = value;
                    });
                  },
                ),

The error is:错误是:

a non null string must be provided to a text widget必须向文本小部件提供非 null 字符串

Try adding a fallback text in the Text widget尝试在文本小部件中添加后备文本

Text(AppLocalizations.of(context).translate('Do you accept the terms and conditions?' ?? 'Do you accept the terms and conditions?');

If you want it to be translated, you have to check your folder: assets > lang如果你想翻译它,你必须检查你的文件夹:assets > lang

You will see all the translations that are in your project, I have put the following in the English one:您将看到项目中的所有翻译,我将以下内容放在英文版中:

"DoYouAcceptTheTermsAndConditions?": "Do you accept the terms and conditions?", "DoYouAcceptTheTermsAndConditions?": "您接受条款和条件吗?",

And in Spanish:西班牙语:

"DoYouAcceptTheTermsAndConditions?": "¿Aceptas los términos y condiciones?", "DoYouAcceptTheTermsAndConditions?": "¿Aceptas los terminos y condiciones?",

If you have any questions, you can ask me questions: D有问题可以问我:D

EDIT: My code now it looks like this:编辑:我的代码现在看起来像这样:

CheckboxListTile ( title: Text(AppLocalizations.of(context).translate('DoYouAcceptTheTermsAndConditions?'), style: TextStyle(fontSize: 18)), value: agree, onChanged: (bool value) { setState(() { this.agree = value; }); }, ), CheckboxListTile ( title: Text(AppLocalizations.of(context).translate('DoYouAcceptTheTermsAndConditions?'), style: TextStyle(fontSize: 18)), value: agree, onChanged: (bool value) { setState(() { this.agree = 值; }); }, ),

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

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