我的串列視圖中有幾個資料,我想檢查是否有任何資料滿足這個 if 條件,讓它留在串列視圖的頂部 0 索引。
ListView.builder(
itemCount: boolS == true ? 7 : data.length,
itemBuilder: (ctx, idx) {
if (boolS == true) {
return shimmer();
}
var index = data[idx];
if (index.userId == userId) {
// make the data stay at the top
}
return Container(
///....
);
),
請問我如何實作這一點。我嘗試將其添加到串列視圖中
itemCount: boolS == true ? 7 : data.length 1,
///...
if(idx == 0 && index.userId == userId) {
return Container();
}
但我不認為那會奏效。所以請你們幫幫我。謝謝
uj5u.com熱心網友回復:
if (index.userId == userId) {
// make the data stay at the top
data.insert(0, index);
data.removeAt(idx 1);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/374037.html
上一篇:使用空格作為串列分隔符
