I need to check all checkboxes, on check of one.
Main Code dynamically creates cards with checkboxes in them
future: getUsers(),
builder: (BuildContext context, AsyncSnapshot snapshot){
if(snapshot.data == null){
return Container(
child: Center(
child: CircularProgressIndicator(),
),
);
}else{
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
ServiceProvider serviceProvider = snapshot.data[index];
return new Card(
shape: selectedName.contains(index)
? new RoundedRectangleBorder(
side: new BorderSide(color: Colors.blue, width: 2.0),
borderRadius: BorderRadius.circular(4.0))
: new RoundedRectangleBorder(
side: new BorderSide(color: Colors.white, width: 2.0),
borderRadius: BorderRadius.circular(4.0)),
child: new Padding(
padding: const EdgeInsets.all(5.0),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text(serviceProvider.name, style: TextStyle(fontSize: 20, height: 1.5)),
new Text(serviceProvider.serviceType, style: TextStyle(fontSize: 15, height: 1.5),),
new Text(serviceProvider.phoneNumber, style: TextStyle(fontSize: 15, height: 1.5),),
new Text(serviceProvider.address, style: TextStyle(fontSize: 15, height: 1.5),),
new Text(serviceProvider.location, style: TextStyle(fontSize: 15, height: 1.5),),
new Text(serviceProvider.emailAddress, style: TextStyle(fontSize: 15, height: 1.5),),
Container(
child: ButtonBar(
children: <Widget>[
new Checkbox(
value: selectedName.contains(serviceProvider.name),
onChanged: (value) {
setState(() {
if(value){
selectedName.add(serviceProvider.name);
}else{
selectedName.remove(serviceProvider.name);
}
});
// selectedName.add(serviceProvider.name);
print(selectedName);
}),
Now, I have a persistentFooterButton widget that has a single checkbox. On checking this checkbox, I want the main code checkboxes to get selected.
PersistentFooterButtons widget
Checkbox(
value: selected,
onChanged: (value) {
setState(() {
if(value){
selectedName.clear();
selectedName.addAll(Iterable<int>.generate(snapshotData.length).toList());
}else{
selectedName.clear();
}
});
print(selectedName);
}),
How can I got about doing this?
Aucun commentaire:
Enregistrer un commentaire