【发布时间】:2020-12-16 06:17:09
【问题描述】:
我有一个存储在“待办事项”类型列表中的任务列表。我想遍历列表并为每个项目创建一张卡片,并且我希望能够在长按时拖动这些卡片并重新排序。
这是我获得今天任务的方式:
List<Todo> todayTasks = [];
for (var i = 0; i < _todos.length; i++) {
if (_todos[i].deadline != null) {
if (_todos[i].deadline.substring(0, 11) ==
todayDate.toString().substring(0, 11)) {
todayTasks.add(_todos[i]);
}
}
}
这就是我创建卡片的方式:
for (var todo in todayTasks)
new Card(
shadowColor: Colors.black,
child: ListTile(
onTap: () => model.updateTodo(
todo.copy(isCompleted: todo.isCompleted == 1 ? 0 : 1)),
contentPadding:
EdgeInsets.symmetric(horizontal: 0, vertical: 8.0),
leading: CircularCheckBox(
onChanged: (value) =>
model.updateTodo(todo.copy(isCompleted: value ? 1 : 0)),
value: todo.isCompleted == 1 ? true : false,
materialTapTargetSize: MaterialTapTargetSize.padded,
),
trailing: IconButton(
icon: Icon(Icons.delete_outline),
onPressed: () => model.removeTodo(todo),
),
title: Text(
todo.name,
style: TextStyle(
fontSize: 18.0,
fontFamily: 'Roboto',
fontWeight: FontWeight.w600,
color: todo.isCompleted == 1
? Colors.grey[500]
: Colors.black,
decoration: todo.isCompleted == 1
? TextDecoration.lineThrough
: TextDecoration.none,
),
),
),
),
【问题讨论】:
-
这能回答你的问题吗? Flutter Sortable Drag And Drop ListView