例如,当您使用 Colors.blue 时,这将返回一个常量 Color 对象,但如果您选择使用阴影,即 Colors.blue[300],则该对象不是常量。这很重要,例如,当您有一个采用可选 Color 参数的方法时,其默认值必须是常量。那么我们如何使 Color shade 保持不变呢?
static const Color mainColor = Colors.blue \\All good!
static const Color shade = Colors.blue[400] \\ERROR: Const variables must be initialized with a constant value
Run Code Online (Sandbox Code Playgroud) flutter ×1