gpt4 book ai didi

dart - 如何禁用复选框 flutter

转载 作者:IT王子 更新时间:2023-10-29 06:35:34 30 4
gpt4 key购买 nike

我在 ListTile 中使用 Checkbox,如下所示:

 ListTile(
leading: Checkbox(
value: _isChecked,
onChanged: (v) {
setState(() {
_isChecked = !_isChecked;
});
},
),
title: Text("is Bathroom"),
);

如何禁用复选框。我知道 Checkbox 小部件是无状态的。但是有没有在material 分包中提供的任何其他Widget 可以做到这一点。类似 InputDecorator 的东西。

我对 DropdownButton 也有同样的疑问。我按如下方式使用它从下拉列表中选择表单中的项目。

             InputDecorator(
decoration: InputDecoration(
labelText: "Type",
hintText: "Choose the type",
),
isEmpty: _type == null,
child: DropdownButton<int>(
value: _type,
isDense: true,
onChanged: (value) {
setState(() {
_type = value;
});
},
items: _buildDropdownItemList(),
),
);

我尝试了 InputDecoration 中的 enable 参数,但这只是改变了装饰。用户仍然可以更改选择。

最佳答案

您可以将 null 传递给 onChanged属性,这将禁用复选框。

关于dart - 如何禁用复选框 flutter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52174090/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com