Error: Method invocation is not a constant expression

Elkhan Jafarov

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

Vladimir Gadzhov

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error: Method invocation is not a constant expression on ElevatedButton.styleFrom

How to identify if an expression is 'method invocation'?

dynamic method invocation in expression tree

"expected constant expression" Error

Dart: Constant evaluation error. The method '[]' can't be invoked in a constant expression

Error: Not a constant expression. (Flutter)

Compile error: Constant expression required

VBA - error "Constant expression require "

POST method in ajax give an error ' Illegal invocation '?

Method invocation error when using PSCredential in Powershell

Getting an invocation error while unit testing the method

Undefined method and uninitialized constant error

'Constant Expression Required' Error while keeping formal argument as a constant

Error: expression must have constant value. For a Clearly Constant Value

SystemVerilog not recognizing constant: Error: Range must be bounded by constant expression

Maven android plugin error "constant expression required"

Constant expression required error in switch statement with strings

Constant expression required error on the switch case for onRequestPermissionResult

constant expression required error when run this program

MS Visual Studio Error: Expected Constant Expression

"constant expression required" error on function declaration line

error with "expression must have a constant value"

Programming in C: Expected constant expression error

"Declaration Not allowed here" and "Constant Expression" Error in C

static assert c++ - constant expression error

JavaBean setter method invocation error "wrong number of arguments"

Error creating bean with name 'embeddedKafka': Invocation of init method failed

PhpUnit: Custom error messages while testing for method invocation

Error creating bean with name 'entityManagerFactory' Invocation of init method failed