mardi 8 juin 2021

Group Checkbox in ModalBottomSheet Flutter

How to apply group checkbox in modalbottomsheet? I have create group checkbox and its work fine. But when I put it in to the modalbottomsheet the state not instantly changes (need to reopen to see value changes). I do have wrap the checkboxListTile with StatefulBuilder and give StateSetter. Any Solution? Thank you

here my codes

Column(
                          children: [
                            StatefulBuilder(builder:
                                (BuildContext context,
                                    StateSetter setState) {
                              return CheckboxListTile(
                                controlAffinity:
                                    ListTileControlAffinity.leading,
                                value: checkAllPermit,
                                title: Text('Permit', style: TextStyle(fontWeight: FontWeight.bold)),
                                onChanged: (value) {
                                  setState(() {
                                    checkAllPermit = value;
                                    _permitType.forEach((tipePermit){
                                      tipePermit.value = value;
                                    });
                                  });
                                },
                              );
                            }),
                            ListView.builder(
                              shrinkWrap: true,
                              itemCount: _permitType.length,
                              itemBuilder: (context, index) {
                                return StatefulBuilder(builder:
                                    (BuildContext context,
                                        StateSetter state) {
                                  return CheckboxListTile(
                                    controlAffinity:
                                        ListTileControlAffinity.leading,
                                    value: _permitType[index].value,
                                    title: Text(_permitType[index].title),
                                    onChanged: (value) {
                                      state(() {
                                        _permitType[index].value = value;
                                      });
                                    },
                                  );
                                });
                              },
                            ),
                          ],
                        ),



Aucun commentaire:

Enregistrer un commentaire