gpt4 book ai didi

flutter - Flutter中LinearPercentIndicator的不同progressColor

转载 作者:行者123 更新时间:2023-12-03 04:43:47 25 4
gpt4 key购买 nike

我得到3个不同的值; $ finalD,$ finalA,$ finalS
因此,我得到了3个不同的linearPercentIndicator;

//linear1
new Text(" $finalD "),
LinearPercentIndicator(
width: MediaQuery.of(context).size.width - 50,
animation: true,
lineHeight: 25.0,
animationDuration: 2500,
percent: percentage,
center: Text(message),
linearStrokeCap: LinearStrokeCap.roundAll,
progressColor: currentProgressColor(),
),

//linear2
new Text(" $finalA "),
LinearPercentIndicator(
width: MediaQuery.of(context).size.width - 50,
animation: true,
lineHeight: 25.0,
animationDuration: 2500,
percent: percentage1,
center: Text(message1),
linearStrokeCap: LinearStrokeCap.roundAll,
progressColor: currentProgressColor(),
),

//linear3
new Text(" $finalS "),
LinearPercentIndicator(
width: MediaQuery.of(context).size.width - 50,
animation: true,
lineHeight: 25.0,
animationDuration: 2500,
percent: percentage,
center: Text(message),
linearStrokeCap: LinearStrokeCap.roundAll,
progressColor: currentProgressColor(),
),

LinearPercentIndicator(
width: MediaQuery.of(context).size.width - 50,
animation: true,
lineHeight: 25.0,
animationDuration: 2500,
percent: percentage3,
center: Text(message3),
linearStrokeCap: LinearStrokeCap.roundAll,
progressColor: currentProgressColor(),
),
为了区分颜色,我使用 currentProgressColor()来表示那些 $ finalD,$ finalA,$ finalS
currentProgressColor(){
//for $finalD
if (finalD < 10) {
return Colors.green;
}else if(finalD < 14) {
return Colors.yellow;
}else if(finalD < 21){
return Colors.orange;
}else if(finalD < 28){
return Colors.deepOrangeAccent;
}else{
return Colors.red;
}

//for &finalA
else if(finalA < 8){
return Colors.green;
}else if(finalA < 10) {
return Colors.yellow;
}else if(finalA < 15){
return Colors.orange;
}else if(finalA < 20){
return Colors.deepOrangeAccent;
}else if(finalA > 19){
return Colors.red;
}

//for &finalS
else if(finalS < 15){
return Colors.green;
}else if(finalS < 19) {
return Colors.yellow;
}else if(finalS < 26){
return Colors.orange;
}else if(finalS < 34){
return Colors.deepOrangeAccent;
}else{
return Colors.red;
}
}
但它只显示第一个($ finalD),其他的仅显示,而不会更改其颜色。
我应该如何安排他们?还是我还有其他方法可以区分不同颜色的值? :)

最佳答案

方法currentProgressColor()的逻辑不允许您超出else语句else{ return Colors.red; }的所有内容,这之后就是无效代码,这就是为什么finalS和finalA具有与finalD相同的值的原因。最好的解决方案是使用不同的方法,因为当您要基于finalD / A / S返回值时很难以这种方式告诉您(该方法不知道您要使用什么值)

currentProgressColorD(){
//for $finalD
if (finalD < 10) return Colors.green;
else if(finalD < 14) return Colors.yellow;
else if(finalD < 21) return Colors.orange;
else if(finalD < 28) return Colors.deepOrangeAccent;
return Colors.red; //no need of else because it will run this line at the end if the other conditions aren't true
}

currentProgressColorA(){
//for $finalA
if (finalA < 8) return Colors.green;
else if(finalA < 10) return Colors.yellow;
else if(finalA < 15) return Colors.orange;
else if(finalA < 20) return Colors.deepOrangeAccent;
return Colors.red; //no need of else because it will run this line at the end if the other conditions aren't true
}

currentProgressColorS(){
//for $finalS
if (finalS < 15) return Colors.green;
else if(finalS < 19) return Colors.yellow;
else if(finalS < 26) return Colors.orange;
else if(finalS < 34) return Colors.deepOrangeAccent;
return Colors.red; //no need of else because it will run this line at the end if the other conditions aren't true
}

关于flutter - Flutter中LinearPercentIndicator的不同progressColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62648250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com