Search code examples
flutterdartcolors

How to change the color of inactive/disabled title/subtitle in ListTile Flutter?


I have a problem with changing the color of title/subtitle/leading of the disabled/inactive ListTile in Flutter.

My widget looks like this: ListTile Widget

ListTile has a trailing Checkbox and it's checked. And the color of title/subtitle is light blue. I want to change this color, but don't know how. I tried to change it with ThemeData:

ThemeData(
    textTheme: TextTheme(
      subtitle1: TextStyle(
        color: Colors.grey[500],
      ),
    ),
  ),

But it works only for unchecked Checkbox, after it's checked the title/subtitle becomes light blue, but I want it to be grey :( Where does thic color come from? What else I can try? I think I have this problem since I upgraded Flutter to 3.24.0, before that everything was fine. I am on Flutter Web and unfortunatelly can't use DevTool Inspector.


Solution

  • I've just found a solution, but I think there could be another one, maybe with ThemeData, so I could define the color for every ListTile widget and don't use an additional widget to change it.

    It's possible to change the color of inactive title/subtitle/leading with ListTileTheme like this:

    ListTileTheme(
      selectedColor: Colors.grey,
      child: ListTile(
        leading: Icon(Icons.featured_play_list_outlined),
        title: Text('Title'),
        subtitle: Text('Subtitle'),
                      ),
                  );
    

    So basically I have to wrap ListTile with a ListTileTheme and use selectedColor property and it does the job! The color of inactive title/subtitle/leading changes.