I have a checkbox in a stateful widget :
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Transform.scale(
scale: 1.3,
child: Checkbox(
side: MaterialStateBorderSide.resolveWith(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return const BorderSide(
width: 2, color: Color(0xff34495E));
}
return const BorderSide(
width: 1, color: Color(0xffB0BEC1));
},
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5)),
activeColor: Color(0xff34495E),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
visualDensity: VisualDensity(horizontal: -4, vertical: -4),
value: value,
onChanged: (value) {
setState(() {
this.value = value;
});
},
),
),
SizedBox(
width: 10,
),
Text(
'Select all',
style: GoogleFonts.poppins(
color: Colors.black87,
fontSize: 12,
fontWeight: FontWeight.w400),
),
],
),
And have checkboxes in a DIFFERENT stateful widget ( in a list tile ) :
Visibility(
visible: controller.isCheboxVisible.value,
child: Transform.scale(
scale: 1.3,
child: Checkbox(
side: MaterialStateBorderSide.resolveWith(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return const BorderSide(
width: 2, color: Color(0xff34495E));
}
return const BorderSide(
width: 1, color: Color(0xffB0BEC1));
},
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5)),
activeColor: Color(0xff34495E),
//materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
//visualDensity: VisualDensity(horizontal: -4, vertical: -4),
value: isChecked,
onChanged: (value) {
setState(() {
this.isChecked = value;
});
},
),
),
)
How do i make the first checkbox to Select all & Un-select all checkboxes in the other stateful widget?
I have tried using a package on pub.dev but it didn’t turn out good, i also don’t like the fact that i have to use a third party package for the simplest of things.
Please i need guidance on this.
Thanks
2
Answers
You should create a controller in DIFFERENT stateful widget
You should pass the controller in your widget
and call this in first widget
To selected and deselect all, we need to communicate the state between widget. callback method is helpful here.