Invalid constant error message for item.header.

It is a boolean value representing if the list tile is going to have a bold or normal font-weight.

 child: ListTile(
        key: ValueKey(item.stuffId),
        title: Text(
          item.name,
          style: const TextStyle(
            color: Colors.blue,           
            fontWeight: item.header == true ? FontWeight.bold : FontWeight.normal,                   
          ),
        ),

Here is the list that I used:

  final List<Stuff> _items = [
    Stuff(stuffId: "1", name: "Toiletries", header: true),
    Stuff(stuffId: "2", name: "Toothpaste", header: false),
    Stuff(stuffId: "3", name: "Hair brush", header: false),
    Stuff(stuffId: "4", name: "Nail clippers", header: false),
  ];

enter image description here

'Toiletries' is the header and therefore supposed to be bold.

2

There are 2 best solutions below

0
On BEST ANSWER
ListTile(
        key: ValueKey(item.stuffId),
        title: Text(
          item.name,
          style: TextStyle( //  remove const here 
            color: Colors.blue,           
            fontWeight: item.header == true ? FontWeight.bold : FontWeight.normal,                   
          ),
        ),
2
On

item.header will get/check on runtime, it cant be const , remove const

style: TextStyle(

Find more about What is the difference between the "const" and "final" keywords in Dart?