Home > Software design >  error: The values in a const list literal must be constants. Flutter
error: The values in a const list literal must be constants. Flutter

Time:10-13

can any one tell me why is there an error. im a beginner in flutter. can any one help.

this is the code, the error is on the onpressed fucntion.

Expanded(
                child: TextButton(
                  onPressed: () {},
                  child: Padding(
                    padding: EdgeInsets.all(16.0),
                    child: Image(
                      image: AssetImage('images/dice1.png'),
                    )
                  ),
    
                ),
    
              ),

error:

error: Invalid constant value. (invalid_constant at line 3)
error: The values in a const list literal must be constants. (non_constant_list_element at line 3)

CodePudding user response:

Don't use the const keyword if you are not using fixed values. Flutter uses the const keyword as an indicator for a widget to never rebuild as it will get evaluated at compile time and only once.

  • Related