I have a custom list view with selectable items.And I am trying to select all items automatically present above the one I selected. For Ex: Suppose there is 10 items in the list view and i selected 5th then it should select all the items available above 5th. i.e(1,2,3,4) and when i deselect 3rd item 1,2,3 items should deselected automatically
return CheckboxListTile(
activeColor: const Color.fromARGB(
255, 243, 243, 243),
checkColor: UIGuide.light_Purple,
selectedTileColor:
UIGuide.light_Purple,
value: value.selecteCategorys
.contains(value.feeList[index]
.installmentName ??
'--'),
onChanged: (bool? selected) async {
value.onFeeSelected(
selected!,
value.feeList[index]
.installmentName,
index,
value.feeList[index].netDue);
},
title: Text(
value.feeList[index].netDue ==
null
? '--'
: value.feeList[index].netDue
.toString(),
textAlign: TextAlign.end,
),
secondary: Text(
value.feeList[index]
.installmentName ??
'--',
),
);
2
Answers
Note, this example isn’t perfect, but it’s a working example that can get you thinking, as I don’t know the bigger picture
Here’s my approach:
get the widget and index of the currently selected value using
.indexOf()
loop over all the widgets until the previously gotten index
Code example
create a class called
CheckBoxModel
:and then, generated 30 widgets:
and used it correspondingly:
Here’s a complete runnable snipppet:
do something like this :
1 – get index of selected item
2 – in the callback fun of checkbox do
let say we have list of items named by items