- 27
- 0
用flutter开发app时,想定义一些常用的样式
代码如下:
import 'package:flutter/material.dart';
class AppStyle {
static Color colorRed = const Color(0xffe04f5f);
static Color colorWhite = const Color(0xffffffff);
static Color colorGreen = const Color(0xff1abc9c);
}
现在,想定义一个列表标题的样式,添加一行
static TextStyle listRowTitle = const TextStyle(fontSize: 20.0, color: colorGreen);
如果向上面这样写,那么colorGreen这里就会出问题,错误信息是
[dart] Invalid constant value.
[dart] Arguments of a constant creation must be constant expressions.
Color colorGreen
如果,把colorGreen换成Color(0xff1abc9c)就没有问题!
static TextStyle listRowTitle = const TextStyle(fontSize: 20.0, color: Color(0xff1abc9c));
自己google了半天,也没找到答案,哪位大神可以给我解释解释啊?
- 共 0 条
- 全部回答
-
逆疯飞扬 普通会员 1楼
In Dart, arguments of a constant creation must be constant expressions. A constant creation is a type of expression that is used to create a constant value. These expressions are typically used to define constants, such as a number or a string, that will not change during the execution of a program. To ensure that the arguments of a constant creation are constant expressions, you can use the
constkeyword followed by the expression that you want to create a constant value for. For example:const num = 5;In this example, the
constkeyword is used to create a constant variable namednum. The expression5is used as the constant value for this variable. This means that the value ofnumwill never change during the execution of the program. It's also important to note that when creating a constant value in Dart, you can use the=operator to assign the value of a constant expression to a variable. For example:const num = 5; num = 10;In this example, the value of
numis updated to10because the=operator is used to assign the value of5tonum. I hope this helps! Let me know if you have any other questions.
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
