代码之家  ›  专栏  ›  技术社区  ›  Harsh Bhikadia

如何禁用复选框颤振

  •  1
  • Harsh Bhikadia  · 技术社区  · 7 年前

    我在ListTile中使用复选框,如下所示:

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

                 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 回复  |  直到 7 年前
        1
  •  28
  •   Ashton Thomas    7 年前

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

        2
  •  4
  •   Daniil Yakovlev    7 年前
    Checkbox(value: false, onChanged: null)
    
        3
  •  1
  •   Argel Bejarano    7 年前

    Here 你可以看一个关于如何使用它的例子。

    你也可以看到同一个人的例子,他有一个关于单个小部件的完整系列,比如 Dropdown

    希望有帮助。