作為一個Column我添加的孩子,例如這個小部件,就像這樣
Column(
children: [
... other Widgets above ...
Chip(
label: Text(
myItem.properties['Status'].currentValue,
style: TextStyle(
color: Colors.white,
fontSize: 10,
),
),
backgroundColor: Colors.blue,
shadowColor: Colors.grey[60],
),
... other Widgets below ...
]
)
從現在開始我沒有一個properties['Status'],而是幾個properties[...]我想Chip(...)用幾個Chip()s 代替。
我可以以某種方式操作properties,它回傳幾個Chip()s 并將其放在Columnschildren串列中的 inline 之上嗎?
uj5u.com熱心網友回復:
如果要串聯使用,可以使用擴展運算子或陣列析構運算子,如下所示:
Column(
children: [
// ... other Widgets above ...
// use the spread (...) operator in front of
// the mapping method that returns a List<Clip> widgets,
// and add all chips inside the array
// assuming that properties['Status'] is an array of some sort
...properties['Status'].map((p) {
return Chip(
label: Text(
p.currentValue, // consume here the object in the iteration
style: TextStyle(
color: Colors.white,
fontSize: 10,
),
),
backgroundColor: Colors.blue,
shadowColor: Colors.grey[60],
);
}).toList(),
// ... other Widgets below ...
]
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/439625.html
