如何在flutter中实现左右滑动

How to achieve swipe right or left in flutter

我正在制作一个待办事项列表应用程序。我想实现向右滑动删除和向左滑动标记,就像一些电子邮件应用程序一样。

我知道Dismissible Widget可以实现滑动删除和secondaryBackground可以做其他方式swipe.But我不知道滑动到其他方式时如何调用其他功能

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')),
        );

确定您滑动的方向

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 
   }
 },