listview - 列表项之间的 Flutter SliverList 分隔符/分隔符

标签 listview flutter

使用 ListView.separated 我们可以在列表项之间添加 Divider(),但是,一旦我转换到 SliverList,我就看不到我的分隔线了。

delegate: SliverChildBuilderDelegate(
            // displays the index of the current item.
            (context, index) => new ListTile(
              title: Text(_sagItems[index].manufacturer, style: TextStyle(fontSize: 18),),
              subtitle: Text(_sagItems[index].model, style: TextStyle(fontSize: 16)),
                onTap: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => DetailScreen(sagitem: _sagItems[index]),
                    ),
                  );
                },
              ),
              //DIVIDER NOT WORKING HERE
              Divider(color: Colors.blueGrey),
              childCount: _sagItems.length,
          ),

SliverList添加分频器的关键是什么?

最佳答案

你可以这样做:

      delegate: SliverChildBuilderDelegate(
            (BuildContext context,int index){
              if(index.isOdd){
                return Divider(color: Colors.blueGrey);
              }
              return ListTile(
              title: Text(_sagItems[index~/2].manufacturer, style: TextStyle(fontSize: 18),),
              subtitle: Text(_sagItems[index~/2].model, style: TextStyle(fontSize: 16)),
                onTap: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => DetailScreen(sagitem: _sagItems[index~/2]),
                    ),
                  );
                },
              );

              },
             childCount: (_sagItems.length * 2)-1,
          ),

关于listview - 列表项之间的 Flutter SliverList 分隔符/分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57715210/

相关文章:

javascript - 在 list-style-type 而不是 list-style-image 中添加图像

c# - 在页面加载时,使用 listview 和 datapager 导航到 listviewitem 所属的特定页面?

java - setOnClickListener 返回正确的位置但错误的项目

flutter - 当应用程序关闭时在 Flutter 中推送通知

flutter - Flutter使用嵌套字典/ map

flutter - 如何使容器的宽度与其高度相匹配

java - 在数组适配器类中设置 TextView 的值时出现空指针异常 - Android

java - 在 ListView 中显示来自 Firebase 的数据时出错

flutter - 无法构建 build_runner :build_runner:Try using an explicit extension application of the wanted extension or hiding unwanted extensions from scope

flutter - 如何在 Dart 的 .map 方法中进行传递/继续?