我正忙于嘗試從后端字串值在前端創建一個 if 陳述句

上面的圖片是從后端和我更換了$ blody1 $用

所以最后它會是這樣的[Guest].length > 1
有沒有辦法將其轉換為真或假,如果沒有任何幫助的指標。我想將邏輯移到后端,但相信我也會在那里遇到同樣的問題。
旁注最終結果應該像 {"color" : "blue"} OR {"color" : "orange"}
我的代碼
const start = "\$";
const end = "\$";
final startIndex = str.indexOf(start);
final endIndex = str.indexOf(end, startIndex start.length);
String tValue =
str.substring(startIndex start.length, endIndex);
String tcondition = str.substring(endIndex 1);
print(getValue(tValue).toString() tcondition);
謝謝
uj5u.com熱心網友回復:
你可以像下面的代碼一樣檢查
void main() {
var data = {"body1":["Guest"]};
print(data["body1"][0]=="Guest");//true
}
更新
檢查車身長度
Color color = Colors.green;
if(data["body1"].length>1){
// set your color
color = Colors.red;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/369381.html
