【问题标题】:how to add custom item to last index on listView reverse mode?如何在listView反向模式下将自定义项目添加到最后一个索引?
【发布时间】:2020-01-25 18:15:14
【问题描述】:

我的列表视图是相反的顺序。我想在 listView 反向模式下将自定义项添加到最后一个索引? (至第一项)

      return ListView.builder(
          itemCount: snapshot.data.length + 1,
          reverse: true,
          itemBuilder: (BuildContext context, int index) {
            if (index == snapshot.data.length -1) {
              return Container(
                  child: myEnquiry());
            }
              index -= 1;

            return other_widget();

         }
     );

【问题讨论】:

    标签: flutter dart


    【解决方案1】:
    return ListView.builder(
      itemCount: snapshot.data.length + 1,
      reverse: true,
      itemBuilder: (BuildContext context, int index) {
        if (index == 0) {   // Fix this line.
          return Container(child: myEnquiry());
        }
        index -= 1;
    
        return other_widget();
    
      },
    );
    

    return ListView.builder(
      itemCount: snapshot.data.length + 1,
      reverse: true,
      itemBuilder: (BuildContext context, int index) {
        if (index == snapshot.data.length) {   // Fix this line.
          return Container(child: myEnquiry());
        }
    //    index -= 1;   // Fix this line.
    
        return other_widget();
    
      },
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-03
      • 1970-01-01
      • 2012-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多