I have a "AlertDialog" with a Checklist (CheckboxListTile) and I wanted to add two buttons at the top. One with the option "Select All" and the other "Unselect All". How can I implement these two buttons that handles the state of all the items in the list?
1
-
It comes down to how do you handle each selected item, for example if you create an array of selected items, select all simply adds all items to selected_items array and unselect all will simply clear the selected items arraydlohani– dlohani2020-09-29 15:01:29 +00:00Commented Sep 29, 2020 at 15:01
Add a comment
|
1 Answer
let's assume that you have loads of checkboxes and you assign a value to each of them
List<bool> checkBoxValues;
...
CheckBox(
value: checkBoxValues[0] // or i if you automate this
)
Then you can easily set all values by
CupertinoButton(
child: Text("check all"),
onPressed: () {
setState (() {
for (var i = 0; I checkBoxValues.length < ; i++)
checkBoxValues[i] = true;
});
},
)
2 Comments
Leonidas Yopan
Cool. I'll try that. Thanks
w461
if this helped, accepting or upvoting the answer would be nice :-)