I build a ListView with ExpansionTiles. These Tiles include a number of CheckboxListTile. I have to handle all the checkboxes, but i dont know how to do this. Can somebody help me pls?
class _HomePageState extends State<HomePage> {
List<String> Test = [];
List<String> Test2 = [];
List<bool> listBool = [];
@override
void initState() {
super.initState();
for(int i = 0; i <= 10; i++)
{
Test.add("Test $i");
Test2.add("Hund $i");
listBool.add(false);
}
}
buildCheckBoxListTile() {
List<Widget> listTile = [];
for (int i = 0; i < Test2.length; i++)
listTile.add(
new CheckboxListTile(
title: Text(Test2[i]),
secondary: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
icon: Icon(Icons.add),
onPressed: null
),
Text("Count"),
IconButton(
icon: Icon(Icons.remove),
onPressed: null
),
],
),
value: listBool[i],
onChanged: (bool value){
setState(() {
listBool[i] = value;
});
},
controlAffinity: ListTileControlAffinity.leading,
),
);
return listTile;
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Einkauslsite")),
body: Column(
children: <Widget>[
Expanded(
child: StreamBuilder(
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
return ListView.builder(
itemCount: Test.length,
itemBuilder: (context, index){
return ExpansionTile(
title: Text(Test[index]),
children: buildCheckBoxListTile(),
);
},
);
},
),
),
],
),
);
}
}
The Streambuilder will i use to read files from firestore. How can i handle these huge number of Checkbox value? I think it going to be 100 or 150. Any Ideas?
Thanks for ur help