我有一個裝飾,我希望根據Firebase的回傳值來改變它。 目前,我的裝飾是這樣的
我的裝飾是這樣的
decoration: const BoxDecoration(
邊界。邊界(
左邊。borderSide(
color: getColor(task.status), width: 5) )。
這是我的switch陳述句,我希望它能回傳正確的顏色
。Color getColor(Color status) {
switch (status.toString() ) {
case 'Draft'/span>:
return const Color. fromRGBO(255, 203, 51, 1)。)
case 'posted':
return const Color. fromRGBO(10, 217, 163, 1)。)
case 'offered':
return const Color. fromRGBO(20, 152, 204, 1) 。
case 'Assigned':
return const Color. fromRGBO(14, 116, 178, 1) 。
case 'overdue':
return const Color. fromRGBO(222, 80, 66, 1)。)
default:
return const Color. fromRGBO(144, 163, 167, 1) 。
}
uj5u.com熱心網友回復:
getColor(Color status)
上面這個方法說,你應該傳遞顏色型別,然后你試圖轉換為字串并與 "Draft"、"Posted "等相匹配。我的朋友,根本就沒有這樣的顏色。
首先,如果你得到的錯誤是 "無效的常量值"。請從你的代碼中洗掉常數。它是不需要的。
你的 getColor()
你的getColor()方法看起來很好,而且應該像你所期望的那樣作業。你只需要傳遞正確的值(可能不是顏色型別,但簡單的字串也可以)。
我在flutter dev上試了一下你的代碼,它可以作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/308590.html
標籤:


