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;
}
本質上,我只想替換常量文本樣式上的顏色,而不必手動撰寫代碼,只需替換顏色即可。
uj5u.com熱心網友回復:
您可以使用該方法執行此操作,copyWith并僅呼叫您要修改的變數。https://api.flutter.dev/flutter/painting/TextStyle/copyWith.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/430315.html
上一篇:敏捷研發專案,我們該如何度量?
下一篇:如何創建這樣的時尚AppBar?
