我的页面上有一个ListTile卡片,但我的应用程序中没有AppBar,因此ListTile从页面顶部开始。如果我添加填充,它会将它添加到ListView中的每张卡,然后我可以将卡放在页面的较低位置,我之间会有很大的差距。有没有什么方法可以保持卡片之间我想要的小间隙,但只是在ListView开始之前在顶部有一个更大的间隙?作为参考,我粘贴了下面的代码。 (基本上它是一个Todo列表类型的应用程序,所以有一个FormField从底部弹出,你输入它出现在ListView卡上的任务。)
Widget _buildTodoList() {
DateTime now = DateTime.now();
String formattedDate = DateFormat('EEE d MMM').format(now);
return ListView.builder(
itemBuilder: (context, index) {
if(index < _todoItems.length) {
return ListTile(
onLongPress: () => _promptRemoveTodoItem(index),
title: Card(
elevation: 1.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(23.0),
),
semanticContainer: true,
clipBehavior: Clip.antiAlias,
child: Column(
children: <Widget>[
Container(
child: Stack(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(23.5, 27.5, 0.0, 0.0),
child: Text("?",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: Colors.black54,
),
),
),
Container(
margin: EdgeInsets.fromLTRB(23.5, 58.0, 0.0, 0.0),
child: Text("${_todoItems[index]}",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 12,
color: Colors.black38,
),
),
),
Align(
alignment: Alignment.centerRight,
child: Container(
margin: EdgeInsets.fromLTRB(0.0, 6.5, 20.0, 0.0),
child: Text(formattedDate,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 11,
color: Colors.deepOrange[700],
),
),
),
),
],
),
height: 100,
width: 380,
),
],
),
),
);
}
},
);
}
我不确定我是否理解你的问题是正确的,但如果是 - 我看到了几个解决方案:
您可以为整个ListView
添加填充
Padding(padding: EdgeInsets.only(top: 200.0), child: ListView.builder(...),)
您可以在列表的第一位添加空项:
ListView.builder(itemBuilder: (context, index) {
if (index == 0) {
return SizedBox(height: 200.0,);
} else {
// todo return your ListTile
}
},
itemCount: _todoItems.length + 1,)