我想在“解鎖”后以另一種顏色顯示我的容器。我怎樣才能做到這一點?當接受挑戰時,它顯示為深紫色。解鎖后它應該顯示為黃色。
child: Container(
height: 70, //Size.width * 2,
width: (Size.width - 70) / 4,
decoration: BoxDecoration(
color: ch[index]['isAccepted'] == 0 ?
textWhite.withOpacity(0.3) : Colors.deepPurple,
borderRadius: BorderRadius.circular(9),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: ch[index]['status'] == "unlocked"
? Image.network(ch[index]['image'])
: Image.asset("assets/images/lock.png")),
),
),

第一個盒子已經解鎖,第二個盒子只接受了第三個盒子,沒有做任何接受或解鎖。
uj5u.com熱心網友回復:
創建一個方法。當條件變得更復雜時,這將使您的代碼更具可讀性:
Color getCorrectColor(Map<String, dynamic> statusMap) {
if (statusMap['status'] == "unlocked") {
return Colors.yellow;
}
if (statusMap['isAccepted'] == 0) {
return textWhite.withOpacity(0.3);
}
return Colors.deepPurple;
}
而是這樣做:
BoxDecoration(
color: getCorrectColor(ch[index]),
borderRadius: BorderRadius.circular(9),
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/488076.html
上一篇:如何使用堆疊小部件在CircleAvatar中居中圖示按鈕
下一篇:將按鈕移至底部
