Flutter - Colors and Variable - 我们可以在颜色后面使用 [xxx] 时使用变量吗?

Flutter - Colors and Variable - Can we use a variable when using the [xxx] after the color?

我有一个简单的问题:

这是代码:

BoxDecoration(
                          gradient: LinearGradient(
                              colors: [
                                Colors.blue[100]!,
                                Colors.blue[50]!,
                                Colors.blue[50]!,
                                Colors.blue[100]!
                              ],
                              begin: Alignment.topCenter,
                              end: Alignment.bottomCenter,
                              stops: [0, 0.2, 0.5, 0.8]),
                          border:
                              Border.all(color: Colors.blue[100]!, width: 1.0),
                          borderRadius: BorderRadius.all(
                            Radius.circular(15),
                          ),
                        ),

我正在创建一个特殊的容器,我希望能够将颜色设置为一个参数,这样我就可以拥有一个蓝色、绿色或紫色的容器... 但是因为我在颜色之后使用 [xxx],所以我似乎不能写类似 myColor[100] 的东西,其中“myColor”将是参数。使用时,我可以将“myColor”替换为“Colors.blue”或“Colors.green”等

有办法吗?

简单地做一个接受List<Color>

的函数
  BoxDecoration _simpleBox(List<Color> color, Color borderColor) =>
    BoxDecoration(
      gradient: LinearGradient(colors: color),
      border: Border.all(color: borderColor, width: 1.0),
      borderRadius: const BorderRadius.all(Radius.circular(15))
    );