简体   繁体   中英

Flutter – CheckboxListTile - Override title style

In a CheckboxListTile, when we check the tile, the check box and the title change their color. What I need to achieve is to split the behavior and keep my title widget with the default color.

In this example, I'm trying to replace the title color but the default behavior is still in place and change the title color the same way as the checked icon:

https://dartpad.dev/?id=7f55df6ce3ba094cfe1db680ccc4b400

The only way I found to achieve the goal is to set directly in the widget the color.

Text(
    'Select Example',
    style: TextStyle(color: Colors.red),
  )

I know I can do a custom item do reach this objective but my question is if possible to override the title widget color when the tile is selected in the CheckboxListTile Flutter widget?

Thanks for reading!

Its also weird for me that there are no separate properties for checkbox and text theme, but this is how you can achieve it.

return CheckboxListTile(
      title: DefaultTextStyle(
        style: const TextStyle(color: Colors.white),
        child: widget.child,
      ),
      tileColor: Colors.black,
      selectedTileColor: Colors.black,
      selected: isSelected,
      dense: true,
      value: isSelected,
      onChanged: (v) => setState(() => isSelected = !isSelected),
      controlAffinity: ListTileControlAffinity.leading,
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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