简体   繁体   English

如何在flutter中更改checkBoxListTile内的复选框颜色?

[英]How to change the checkBox color inside the checkBoxListTile in flutter?

I am using the CheckBoxListTile like this,我正在像这样使用CheckBoxListTile

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?怎么做?

try wrap CheckBoxListTile with Theme widget and choose color at unselectedWidgetColor properties.尝试用 Theme 小部件包装CheckBoxListTile并在unselectedWidgetColor属性中选择颜色。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM