简体   繁体   English

错误:方法调用不是常量表达式

[英]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:颜色:Colors.black.withOpacity(0.6),当我尝试运行这个时出现这个错误:

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请帮助解决这个问题

You need to remove the const before ListTile, because Colors.grey.withOpacity(0.6) isn't a constant value.您需要删除 ListTile 之前的常量,因为 Colors.grey.withOpacity(0.6) 不是常量值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM