Error: Method invocation is not a constant expression.
color: Colors.black.withOpacity(0.6),
I get this error when I try run this:
body: ListView.builder(
itemCount: 15,
itemBuilder: (context, i) => const ListTile(
title: Text("Bitcoin",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 24,
)),
subtitle: Text("\$20000",
style: TextStyle(
color: Colors.grey.withOpacity(0.6), //error in this line
fontWeight: FontWeight.w700,
fontSize: 14,
)),
),
),
How can I solve this?
You need to remove the const before ListTile
, because Colors.grey.withOpacity(0.6)
isn't a constant value.
body: ListView.builder(
itemCount: 15,
itemBuilder: (context, i) => ListTile(
title: const Text("Bitcoin",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 24,
)),
subtitle: Text("\$20000",
style: TextStyle(
color: Colors.grey.withOpacity(0.6), //error in this line
fontWeight: FontWeight.w700,
fontSize: 14,
)),
),
),