You will see I am generating a series of checkboxes dynamically within a ListBuilder and I need to identify which of them is marked as true, the problem is that I can't think of how to do it.
Here you have the list code which is dynamically generated through a list of strings:
return SlideTile(
title: "Incidencia del solicitante",
listBuilder: Container(
height: MediaQuery.of(context).size.height * 0.25,
child: MediaQuery(
data: MediaQuery.of(context).removePadding(
removeTop: true,),
child: ListView.builder(
padding: EdgeInsets.fromLTRB(
10, 0, 10, 5),
primary: false,
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: blocAssistant.incidencias_solicitante.length,
itemBuilder: (context, index) {
return checkBox(text: blocAssistant.incidencias_solicitante[index]);
}
)
)
),
desc: "Aqui debe indicar el tipo de error de la incidencia.",
);
And here you have the code of the checkboxes of which I need to recognize their status individually.
class checkBox extends StatefulWidget {
const checkBox({
required this.text,
});
final String text;
@override
State<checkBox> createState() => _CheckBoxState();
}
class _CheckBoxState extends State<checkBox> {
bool checkboxListTileValue = false;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return CheckboxListTile(
value: checkboxListTileValue,
onChanged: (newValue) {
setState(() => checkboxListTileValue = newValue!);
},
title: Text(
widget.text,
style: MainTheme.title2.override(
fontFamily: 'Montserrat',
fontWeight: FontWeight.w400,
fontSize: 16,
),
),
tileColor: MainTheme.tertiaryColor,
activeColor: MainTheme.primaryColor,
checkColor: MainTheme.tertiaryColor,
controlAffinity: ListTileControlAffinity.trailing,
);
}
}
CodePudding user response:
If you want to add 10 checkboxes
then add 10 bool values such as
bool ischanged = false;
bool ischanged1 = false;
bool ischanged2 = false;
bool ischanged4 = false;
bool ischanged5 = false;
bool ischanged6 = false;
bool ischanged7 = false;
bool ischanged8 = false;
bool ischanged9 = false;
CodePudding user response:
Under the class keep the bool value to false.
bool ischanged = false;
checkbox(
value: ischanged,
onchanged(value) {
setstate ((){
ischanged = value!;
}
)
This way you can recognize their status individually.