Issue
i have multiple checkboxes .. in which you can select more than one checkbox ... like this:
for (var a in user.poll.questions[i].options) {
children.add(
new Row(
children: [
new Checkbox(
value: questionList.contains(a.id),
onChanged: (bool newValue) {
setState(() {
//if (questionList.length < user.poll.questions[i].maxChoice){
newValue
? questionList.add(a.id)
: questionList.remove(a.id);
//}
});
answers[user.poll.questions[i].id] = questionList;
}),
new Text(
a.text,
style: TextStyle(fontSize: 16.0),
),
],
),
);
}
but i want to limit number of checked boxes .. am getting the max choices number from json .. how to limit the selection of checkedboxes by it?
for example if
int maxChoices = 3;
how can i let the user selects maximum of 3 checkboxes?
Solution
Don't you want to do something like this?
(newValue && questionList.length >= maxChoices)
? showAlert() : setState(() {
newValue
? questionList.add(a.id)
: questionList.remove(a.id);
});
Answered By - Andrey Turkovsky
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.