lundi 12 avril 2021

Flutter - Load CheckBox Checked

I am developing an application that contains a CheckBoxListTile with the checked CheckBox saved in the database with the name of the selected item.

Output Example: [ingredient 1, ingredient 2]

I need to load another CheckBoxListTile on another screen with the marked CheckBox that were saved in the database

             Container(
                    height: 220,
                    width: 200,
                    child: ListView.builder(
                      shrinkWrap: true,
                      itemBuilder: (context, index) {
                        return CheckboxListTile(
                          title: Text(
                            _ingredientList[index].nameIngredient,
                            style: TextStyle(
                                fontSize: 16,
                                fontFamily: 'Montserrat',
                                fontWeight: FontWeight.bold,
                                color: Colors.grey),
                          ),
                          value: isCheckedEdit.contains(_ingredientList[index].nameIngredient),
                          onChanged: (value) {
                            if (value) {
                              setState(() {
                                isCheckedEdit
                                    .add(_ingredientList[index].nameIngredient);
                                print(isCheckedEdit);
                              });
                            } else {
                              setState(() {
                                isCheckedEdit.remove(
                                    _ingredientList[index].nameIngredient);
                                print(isCheckedEdit);
                              });
                            }
                          },
                        );
                      },
                      itemCount: _ingredientList.length,
                    ),
                  ),



Aucun commentaire:

Enregistrer un commentaire