Flutter 颤振中线性指示器的不同颜色
我得到了3个不同的值$决赛,$finalA,$决赛 因此,我得到了3个不同的线性指示器Flutter 颤振中线性指示器的不同颜色,flutter,dart,indicator,Flutter,Dart,Indicator,我得到了3个不同的值$决赛,$finalA,$决赛 因此,我得到了3个不同的线性指示器 //linear1 new Text(" $finalD "), LinearPercentIndicator( width: MediaQuery.of(context).size.width - 50, animation: true, lineHeight: 25.0, animation
//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、$final
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;
}
}
currentProgressColor(){
//最后一美元
如果(最终值<10){
返回颜色。绿色;
}否则,如果(最终值<14){
返回颜色。黄色;
}否则,如果(最终值<21){
返回颜色。橙色;
}否则,如果(最终值<28){
返回颜色.deeporangeacent;
}否则{
返回颜色。红色;
}
//菲娜拉酒店
否则,如果(最终<8){
返回颜色。绿色;
}否则,如果(最终<10){
返回颜色。黄色;
}否则,如果(最终<15){
返回颜色。橙色;
}否则,如果(最终<20){
返回颜色.deeporangeacent;
}否则,如果(最终结果>19){
返回颜色。红色;
}
//总决赛
否则如果(总决赛<15){
返回颜色。绿色;
}否则如果(总决赛<19){
返回颜色。黄色;
}否则如果(总决赛<26){
返回颜色。橙色;
}否则如果(总决赛<34){
返回颜色.deeporangeacent;
}否则{
返回颜色。红色;
}
}
但它只显示了第一个($finalD),其他人只是跟随,并没有改变它应该是什么颜色
我该怎么安排呢?或者有没有其他方法可以让我用不同的颜色来区分这些值?:) 方法currentProgressColor()的逻辑不允许您超越else语句
else{return Colors.red;}
之后的所有内容都是死代码,这就是为什么final和finalA将具有与finalD相同的值。最好的解决方案是使用不同的方法,因为当您希望返回基于finalD/a/s的值时,很难用这种方法来判断(该方法不知道您想要使用什么值)
currentProgressColorD(){
//最后一美元
if(finalD<10)返回Colors.green;
否则如果(finalD<14)返回Colors.yellow;
否则如果(finalD<21)返回Colors.orange;
否则如果(finalD<28)返回Colors.deeporangeacent;
return Colors.red;//不需要else,因为如果其他条件不成立,它将在末尾运行此行
}
currentProgressColorA(){
//最后一美元
如果(finalA<8)返回颜色。绿色;
否则如果(finalA<10)返回Colors.yellow;
否则如果(finalA<15)返回Colors.orange;
否则如果(finalA<20)返回Colors.deeporangeacent;
return Colors.red;//不需要else,因为如果其他条件不成立,它将在末尾运行此行
}
currentProgressColorS(){
//美元决赛
如果(总决赛<15)返回颜色。绿色;
否则如果(总决赛<19)返回颜色。黄色;
否则如果(总决赛<26)返回颜色为橙色;
否则如果(总决赛<34)返回颜色。深橙色每分;
return Colors.red;//不需要else,因为如果其他条件不成立,它将在末尾运行此行
}
使用开关可能会起作用。
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
}