我正在尝试使用复选框在 Flutter 中显示/隐藏 2 个文本表单字段。我尝试了下面的代码,认为它会使用复选框的状态来显示字段。但这不起作用。
Checkbox 本身确实在 true 和 false 之间切换,但布局没有变化。
CheckboxListTile(
title: Text("Do you want to update your price?"),
controlAffinity: ListTileControlAffinity.leading,
value: priceupdate_value,
onChanged: (bool priceupdateValue) {
setState(() {
priceupdate_value = priceupdateValue;
});
if(priceupdate_value == true){
Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: 'New Price',
),
),
TextFormField(
decoration: InputDecoration(
labelText: 'Update Other Information',
),
),
],
);
}
},
),
Run Code Online (Sandbox Code Playgroud)