flutter - Flutter ReorderableListView - how to add divider
问题描述
I have a list created using ReorderableListView. I want to have a separate each list item with a Divider. I am looking for a clean solution, similar to ListView.separated(), however I can't find anything similar for ReorderableListView. In my code at the moment I am using a column widget to which I add a divider for every item but this is very "hacky". Do you know how this could be implemented in a better way?
I'm looking for divider like here:
My Code:
Main Page:
Widget _buildList(RoutinesState state) {
if (state is RoutinesFetched || state is RoutinesReordered) {
List<CustomCard> cards = [];
state.routines.forEach(
(e) {
cards.add(
CustomCard(
key: PageStorageKey(UniqueKey()),
title: e.name,
onTap: () {
Navigator.pushNamed(
context,
RoutineDetails.PAGE_ROUTE,
arguments: RoutineDetailsArgs(e),
);
},
includeDivider: cards.isNotEmpty,
),
);
},
);
return ReorderableListView(
children: cards,
onReorder: (int from, int to) => {
bloc.add(ReorderRoutine(fromIndex: from, toIndex: to)),
},
);
}
return Container(
child: Text("No routines found yet :( "),
);
}
Custom Card Widget:
@override
Widget build(BuildContext context) {
List<Widget> columnItems = [];
if (this.includeDivider) {
columnItems.add(Divider());
}
columnItems.add(ListTile(
leading: CircleAvatar(
child: Icon(Icons.fitness_center),
),
title: Text(this.title),
subtitle: Text("Weights"),
trailing: ActionChip(
label: Icon(Icons.play_arrow),
backgroundColor: Color(0xffECECEC),
onPressed: () => null,
),
onTap: this.onTap,
));
return Column(
mainAxisSize: MainAxisSize.min,
children: columnItems,
);
}
解决方案
推荐阅读
- go - 如何使用 ServiceAccount Token 连接到 Kubernetes 集群?
- c - 是否可以在 Windows 中使用 C 更改我的 IP 地址?
- linux - Vagrant 无法在 Ubuntu 20 客户机中挂载 NFS
- javascript - 避免在 Nuxt VueJs 中直接改变道具
- reactjs - React - 在宽屏上显示所有路线,但在移动设备上只显示一条
- javascript - 是的架构:如何在错误消息中添加新行
- c# - C# 中的 UUID_To_BIN 等效项
- oauth-2.0 - PKCE:为什么要对代码验证器进行哈希处理?
- javascript - 在行中使用 HTML 下拉菜单后,从 R Shiny 中的 DT 表中获取当前显示的数据
- laravel - 如何在 laravel 8 中实现多外键