用 getMethod 替换颜色常量值?同时保持其他预定义值

Replacing a color constant value with a getMethod? while maintaining other predefined values

SizedBox(
        height: 50,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: List.generate(
            listCategory.length,
            (index) => Text(
              listCategory[index],
              style: kTabText, ----The constant styled variable ----
            ),
          ),
        ),
      ),

我想要使用的 getColor 方法,

Color getColor() {
late final Color color;
if (_currentPage >= 0 && _currentPage < 0.7) {
  color = listShoes[0].listImage[0].color;
} else if (_currentPage > 0.7 && _currentPage < 1.7) {
  color = listShoes[1].listImage[1].color;
} else if (_currentPage > 1.7 && _currentPage < 2.7) {
  color = listShoes[2].listImage[2].color;
}
return color;

}

本质上我只想替换常量文本样式上的颜色,无需手动编写代码,只需替换颜色即可。

您可以使用方法 copyWith 来完成,并且只调用您想要修改的变量。 https://api.flutter.dev/flutter/painting/TextStyle/copyWith.html