[英]How to achieve swipe right or left in flutter
I am making a todo list app.我正在制作一个待办事项列表应用程序。 I want achieve swipe right to delete and swipe left to mark just like some email app.
我想像某些 email 应用程序一样实现向右滑动删除和向左滑动标记。
I know Dismissible Widget can achieve swipe to delete and secondaryBackground can make other way to swipe.But I don't how to call other function when I swipe to other way.我知道Dismissible Widget可以实现滑动删除,secondaryBackground 可以通过其他方式滑动。但是当我滑动到其他方式时,我不知道如何调用其他 function。
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')),
);
To determine which direction you swiped确定您滑动的方向
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
}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.