【问题标题】:error: The values in a const list literal must be constants. Flutter错误:const 列表文字中的值必须是常量。扑
【发布时间】:2021-11-30 18:32:21
【问题描述】:

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

这是代码,错误是onpressed fucntion。

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

错误:

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)

【问题讨论】:

标签: flutter widget material-design flutter-widget


【解决方案1】:

如果您不使用固定值,请不要使用 const 关键字。 Flutter 使用 const 关键字作为小部件永远不会重新构建的指示符,因为它将在编译时被评估一次。

【讨论】:

    猜你喜欢
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-21
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多