Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error: Method invocation is not a constant expression

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

Please helpto solve this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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,
          )),
    ),
  ),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading