const GradientContainer.purple(
{super.key,
this.colorsList = ***[
const Color.fromARGB(123, 69, 2, 74),
const Color.fromARGB(123, 233, 177, 237)
]***,
this.textToBePlaced = 'New Constructor'});
*** - ***内有错误部分。
我假设这是因为列表是可变的,所以它们不能被视为常量? 如果不是,为什么我会收到此错误?
虽然数组中的项是不变的,但数组本身却不是。
您可以通过在数组前面添加
const
关键字来解决此问题,如下所示:
const GradientContainer.purple(
{super.key,
this.colorsList = const [
const Color.fromARGB(123, 69, 2, 74),
const Color.fromARGB(123, 233, 177, 237)
],
this.textToBePlaced = 'New Constructor'});