使用switch代替if语句和三元,
class FaceStyleImage{
static faceStyleImage(String imageRatio,){
//image是我们需要的,不局限于String类型,可以为其他类型
String image = '';
switch(imageRatio) {
case "0.5625" :
image = 'assets/images/image/123.png';
break;
case "1" :
image = 'assets/images/image/456.png';
break;
default: {
image = 'assets/images/image/789.png';
}
}
return image;
}
}
使用
Image.asset(FaceStyleImage.faceStyleImage('${faceStyleList[index]["imageRatio"]}')),