Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 ----
            ),
          ),
        ),
      ),

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading