[英]Flutter: ListView.Separated set height
如何在 ListView.Separated 中設置每個 ListTile 項目的高度?
我使用 ListView.Seperated 和 ListTile 項目,如下面的代碼所示:
Widget _LocationItem(LocationModel location) => Container(
child: Center(
child: ListTile(
title: Text(location.name),
trailing: Icon(Icons.arrow_right),
),
),
);
// *** BUILD WIDGET
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: Icon(Icons.navigate_before),
title: Text("Location"),
),
body: FutureBuilder<List<LocationModel>>(
future: _locationModel,
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.separated(
itemCount: snapshot.data!.length,
separatorBuilder: (_, __) => const Divider(),
itemBuilder: (context, index) {
var location = snapshot.data![index];
return _LocationItem(location);
});
} else
return Center(child: CircularProgressIndicator());
},
));
}
這是我的代碼的結果:
如您所見,每個文本的頂部和底部都有相當多的額外空間。 如何去除頂部和底部的額外空間?
我試圖設置容器的高度,但它實際上只是刪除了底部空間,看起來不太好。
您將需要編輯ListTile
嘗試ListTile
添加屬性
試試這個 :
Widget _LocationItem(LocationModel location) => Container(
child: Center(
child: ListTile(
title: Text(location.name),
trailing: Icon(Icons.arrow_right),
contentPadding: , // add padding here
),
),
);
感謝大家的幫助,只是意識到 Divider 具有高度屬性。 與此同時,我只是將高度設置為 0,結果更好:
return ListView.separated(
itemCount: snapshot.data!.length,
separatorBuilder: (_, __) => const Divider(
height: 0,
),
itemBuilder: (context, index) {
var location = snapshot.data![index];
return _LocationItem(location);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.