【问题标题】:How to make a particular data go to the top of listview - flutter如何使特定数据进入列表视图顶部 - 颤振
【发布时间】:2022-01-10 12:37:02
【问题描述】:

我的列表视图中有几个数据,我想检查是否有任何数据满足这个 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();
}

但我认为这行不通。所以请你们帮帮我。谢谢

【问题讨论】:

    标签: flutter dart listview


    【解决方案1】:
    if (index.userId == userId) {
        // make the data stay at the top
        data.insert(0, index);
        data.removeAt(idx+1);
        }
    

    【讨论】:

      猜你喜欢
      • 2020-02-05
      • 2020-04-05
      • 1970-01-01
      • 2021-12-21
      • 2019-01-13
      • 2020-06-03
      • 1970-01-01
      • 1970-01-01
      • 2019-08-03
      相关资源
      最近更新 更多