您將看到我在 ListBuilder 中動態生成了一系列復選框,我需要確定其中哪些標記為 true,問題是我想不出如何去做。
這里有通過字串串列動態生成的串列代碼:
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.",
);
在這里你有復選框的代碼,我需要單獨識別它們的狀態。
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,
);
}
}
uj5u.com熱心網友回復:
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;
uj5u.com熱心網友回復:
在類下保持 bool 值為 false。
bool ischanged = false;
checkbox(
value: ischanged,
onchanged(value) {
setstate ((){
ischanged = value!;
}
)
這樣您就可以單獨識別它們的狀態。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/359289.html
下一篇:應用程式啟動后如何繼續制作影片?
