0

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 array Commented Sep 29, 2020 at 15:01

1 Answer 1

2

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;
    });
  },
)
Sign up to request clarification or add additional context in comments.

2 Comments

Cool. I'll try that. Thanks
if this helped, accepting or upvoting the answer would be nice :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.