如何禁用复选框抖动

时间:2018-09-04 21:15:21

标签: dart flutter flutter-layout

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

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

如何禁用该复选框。我知道Checkbox小部件是无状态的。但是材料子包中是否提供了其他任何可以执行此操作的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参数,但这只是改变了装饰。用户仍然可以更改选择。

3 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:2)

Checkbox(value: false, onChanged: null)

答案 2 :(得分:1)

您可以在statefuldwiget中使用setstate更改复选框状态,我将在youtube中找到一个示例。

Here,您可以观看有关如何使用它的示例。

您也可以从一个人那里看到一个例子,他有完整的系列有关各个小部件的信息,例如Dropdown

希望有帮助。