使用 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/