Am trying to select one or more check boxes from a list of check boxes, i have found that the best option is using the checkBoxListTile
widget to implement this.
First i have defined a list and used the widget as follows:
List<String> _texts = ["google.com", "youtube.com", "yahoo.com", "gmail.com"];
Expanded(
child: ListView(
children: _texts
.map((text) => CheckboxListTile(
title: Text(text),
value: _isChecked,
onChanged: (val) {
setState(() {
_isChecked = val;
});
},
))
.toList(),
),
),
check boxes are displayed fine but whenever i click one checkbox all are checked, how can i handle choosing one or more check boxes from the list?
Thank you
3
Answers
The
value
parameter for inCheckboxListTile
is how widget knows whether checkbox is checked or not. When you give all of them samevalue
, all of their state changes.You can keep a seperate list to keep track of if the specific checkbox is checked.
Try below code hope its help to you I have try it other way
Only Single Checkbox Selected:
Your List :
Your Widget:
Full Code:
Result Screen->
Multiple Checkbox Selection
Your List/Map
Your Function:
Your Widget:
Full Example
Result Screen->
Refer Video Tutorial for Flutter Multiselect Dropdown Checkbox on YouTube
Output