Aman Chaudhary
Aman Chaudhary

Reputation: 912

How to change the checkBox color inside the checkBoxListTile in flutter?

I am using the CheckBoxListTile like this,

CheckboxListTile(
            title: Text(
              ourAllnotes[i].note,
              style: TextStyle(color: Colors.white),
            ),
            value: false,
            onChanged: (bool value) {},
            activeColor: Colors.orange,
            checkColor: Colors.white,
            controlAffinity: ListTileControlAffinity.leading,
          )

I could change the color of the checkbox after it is checked, but I cannot change its color before it is checked rather than its default value. How to do that?

Upvotes: 2

Views: 6193

Answers (1)

khoi
khoi

Reputation: 1180

try wrap CheckBoxListTile with Theme widget and choose color at unselectedWidgetColor properties.

  Theme(
    data: ThemeData(unselectedWidgetColor: Colors.white),
    child: CheckboxListTile(
      checkColor: Colors.white,

      title: Text(
        "show password",
        style: TextStyle(
            fontSize: 12, color: Colors.white, letterSpacing: 2),
      ),
      value: checkboxflag,
      onChanged: (newValue) {
        setState(() {
          if (newValue) {
            checkboxflag = newValue;
            _obscureText = false;
          } else {
            checkboxflag = newValue;
            _obscureText = true;
          }
        });
      },
      controlAffinity:
          ListTileControlAffinity.leading, //  <-- leading Checkbox
    ),
  )

Upvotes: 7

Related Questions