mardi 8 janvier 2019

checkbox value on changed is always true

am trying to display an alertdialog with a listview of checkboxes .. like this:

showDialog(
                                context: context,
                                builder: (BuildContext context) {
                                  return AlertDialog(
                                    title: Text(' ', textAlign: TextAlign.right,),
                                    content: Directionality(
                                    textDirection: TextDirection.rtl,
                                    child: Container(
                                      height: 300.0,
                                      width: 300.0,
                                      child: new ListView.builder(
                                          shrinkWrap: true,
                                          itemCount: dropEntitiesList.length,
                                          itemBuilder: (BuildContext context, int index) {
                                            return new Row(
                                              children: [
                                                new Checkbox(
                                                    value: globals.entitiesFilter.contains(dropEntitiesList[index]),
                                                    onChanged: (bool newValue) {
                                                      setState(() {
                                                        dropEntitiesList[index].isClicked = !dropEntitiesList[index].isClicked;
                                                        if (dropEntitiesList[index].isClicked){
                                                          globals.entitiesFilter.add(dropEntitiesList[index].name);
                                                        }else{
                                                          globals.entitiesFilter.remove(dropEntitiesList[index].name);
                                                        }
                                                      });
                                                      print(globals.entitiesFilter);
                                                    }),
                                                new Text(
                                                  dropEntitiesList[index].name,
                                                  style: TextStyle(fontSize: 16.0),
                                                ),
                                              ],
                                            );
                                          }),
                                    ),
                                  ),
                                    actions: <Widget>[
                                      new FlatButton(
                                          child: new Text('انتهيت'),
                                          onPressed: () {
                                            Navigator.of(context).pop(true);
                                          }),
                                      new FlatButton(
                                        child: new Text('إلغاء'),
                                        onPressed: () {
                                          Navigator.of(context).pop(false);
                                        },
                                      )
                                    ],
                                  );

the onchanged newvalue is always true .. and i need to close the dialog and then open it again to see the checked checkboxes .. it will not change immediately when clicked ..

How to solve this?




Aucun commentaire:

Enregistrer un commentaire