Search code examples
fluttertranslate

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


Solution

  • 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; }); }, ),