简体   繁体   中英

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

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

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?",

And in Spanish:

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

If you have any questions, you can ask me questions: 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; }); }, ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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