0

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

我知道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')),
        );
4

1 回答 1

4

确定您滑动的方向

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 
   }
 },
于 2019-09-30T14:11:31.590 回答