i used this command widgets.removeAt(data[index]['title']); but when i tried to uncheck its checkbox not all title of title of checkbox is removed
class _MyHomePageState extends State<MyHomePage> {
List<Widget> widgets=[];
List<Map<String, dynamic>> data = [
{'title': 'checkbox1', 'value': false},
{'title': 'checkbox2', 'value': false},
{'title': 'checkbox3', 'value': false}
];
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body:
Column(
children: [
Column(
children: widgets
),
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount : data.length,
itemBuilder: (context, index) {
return CheckboxListTile(
title: Text(data[index]['title']),
value: data[index]['value'],
onChanged: (value) {
setState(() {
// bool check=data[index]['value'] = value!;
if(data[index]['value'] = value!){
widgets.add(Text(data[index]['title'].toString()));
print(data[index]['title'].toString());
}else{
widgets.removeAt(index);
}
});
});
},
),
],
),
);
[enter image description here](https://i.stack.imgur.com/ZHKje.png)
in that picture checkbox title not removed in console i got this error Value not in range: 2
Aucun commentaire:
Enregistrer un commentaire