admin管理员组文章数量:1410737
I'm using a Dismissible widget to allow users to delete tasks from a ListView. However, the red background of the Dismissible is larger than the actual card size, causing extra spacing between the list items.
Here's my current code for rendering each item:
Widget _dismissibleCard(Task task) {
return Dismissible(
key: UniqueKey(),
background: Container(
alignment: Alignment.centerRight,
color: Colors.red,
child: Icon(
Icons.delete,
color: white,
size: 30,
),
),
child: CustomCard(
title: task.taskDetail,
subtitle: task.taskDetail,
cardColor: cardColor),
onDismissed: (direction) async {
await service.removeTasks(task.key!);
setState(() {
taskList.remove(task);
});
},
);
}
I have tried:
- Setting a fixed height for Dismissible
- Wrapping Dismissible with a SizedBox
- Adjusting padding/margins But none of these have worked. How can I make the red background match the exact height of my CustomCard, so it doesn’t create additional space in the list?
I'm using a Dismissible widget to allow users to delete tasks from a ListView. However, the red background of the Dismissible is larger than the actual card size, causing extra spacing between the list items.
Here's my current code for rendering each item:
Widget _dismissibleCard(Task task) {
return Dismissible(
key: UniqueKey(),
background: Container(
alignment: Alignment.centerRight,
color: Colors.red,
child: Icon(
Icons.delete,
color: white,
size: 30,
),
),
child: CustomCard(
title: task.taskDetail,
subtitle: task.taskDetail,
cardColor: cardColor),
onDismissed: (direction) async {
await service.removeTasks(task.key!);
setState(() {
taskList.remove(task);
});
},
);
}
I have tried:
- Setting a fixed height for Dismissible
- Wrapping Dismissible with a SizedBox
- Adjusting padding/margins But none of these have worked. How can I make the red background match the exact height of my CustomCard, so it doesn’t create additional space in the list?
1 Answer
Reset to default 0You can remove all the fixed height;
Widget get _listView => ListView.builder(
itemCount: taskList.length,
itemBuilder: (context, index) => _dismissibleCard(
taskList[index],
),
);
Also from _dismissibleCard
Widget _dismissibleCard(Task task) {
return Dismissible(
key: UniqueKey(),
background: Container(
alignment: Alignment.centerRight,
color: Colors.red,
child: Icon(Icons.delete, color: white),
),
child: SizedBox(
child: CustomCard(title: task.taskDetail, subtitle: task.taskDetail, cardColor: cardColor),
),
onDismissed: (direction) async {
await service.removeTasks(task.key!);
setState(() {
taskList.remove(task);
});
},
);
}
本文标签: Flutter Dismissible widget causes extra spacing between ListView itemsStack Overflow
版权声明:本文标题:Flutter Dismissible widget causes extra spacing between ListView items - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744878718a2630073.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论