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

Time:02-22

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

The getColor method i'm looking to use,

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;

}

Essentially I only want to replace the color on the constant text style without having to write the code manually, simply replace color only.

CodePudding user response:

You can do it with the method copyWith and call only variables you want to modify. https://api.flutter.dev/flutter/painting/TextStyle/copyWith.html

  • Related