Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable checkbox flutter

I am using Checkbox inside a ListTile like the following:

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

How can I disable the checkbox. I know that the Checkbox widget is stateless. But is there any other Widget provided in material subpackage that can do this. Something like InputDecorator.

Also I have same question with DropdownButton. I am using it as following to choose an item in a form from a dropdown list.

             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(),
                ),
              );

I tried the enable argument in InputDecoration but that just changes the decoration. User can still change the selection.

like image 421
Harsh Bhikadia Avatar asked Sep 04 '18 21:09

Harsh Bhikadia


People also ask

How to disable checkbox after checked in Flutter?

You can pass null to the onChanged property and this will disable the checkbox.

How do you change the size of a checkbox in flutter?

Its better then use Transform. scale(), It would help you to manage the size with scaling functionality..


1 Answers

You can pass null to the onChanged property and this will disable the checkbox.

like image 137
Ashton Thomas Avatar answered Sep 21 '22 15:09

Ashton Thomas