我正在制作待办事项清单应用程序。我想实现向右滑动删除和向左滑动标记,就像某些电子邮件应用一样。
我知道Dismissible Widget可以实现滑动删除操作,secondaryBackground可以进行其他滑动操作。但是,当我以其他方式滑动时,我不知道如何调用其他函数。
return Dismissible(
// Each Dismissible must contain a Key. Keys allow Flutter to
// uniquely identify widgets.
key: Key(item),
// Provide a function that tells the app
// what to do after an item has been swiped away.
onDismissed: (direction) {
// Remove the item from the data source.
setState(() {
items.removeAt(index);
});
// Then show a snackbar.
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text("$item dismissed")));
},
// Show a red background as the item is swiped away.
background: Container(color: Colors.red,child: Icon(Icons.cancel),),
secondaryBackground: Container(color: Colors.green,child: Icon(Icons.check),),
child: ListTile(title: Text('$item')),
);
答案 0 :(得分:2)
确定要刷哪个方向
onDismissed: (direction) {
if(direction == DismissDirection.startToEnd) { // Right Swipe
setState(() {
items.removeAt(index);
});
Scaffold.of(context).showSnackBar(SnackBar(content: Text("$item dismissed")));
} else if(direction == DismissDirection.endToStart) {//Left Swipe
//add event to Calendar
}
},