I have several data in my listview and i want to check if any of the data satisfies this if condition, let it stay at the top of the listview at 0 index.
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(
///....
);
),
Please how do i achieve this. I tried adding this to the listview
itemCount: boolS == true ? 7 : data.length 1,
///...
if(idx == 0 && index.userId == userId) {
return Container();
}
but i don't think that's gonna work. So please can you guys help me out. Thanks
CodePudding user response:
if (index.userId == userId) {
// make the data stay at the top
data.insert(0, index);
data.removeAt(idx 1);
}