Dismissing a Dismissible with Flutter/Dart

后端 未结 5 1210
轻奢々
轻奢々 2021-01-03 17:53

In the majority of the Dismissible examples provided by Flutter, they are dismissing items within a ListView. For example, this.

What I am currently doing is this:

5条回答
  •  佛祖请我去吃肉
    2021-01-03 18:32

    simplest way 1-> set unique id for each item of list with

    var uuid = new Uuid();
    
      new MyItem(title: "Sanjay Singh Bisht",color:"#123ab",uniqueId:uuid.v1()));
    

    as mentioned in above post Dismissible widget required unique id

    2-> now to delete item its simple

    if (items.contains(deletedItem)) {
        setState(() {
          items.remove(deletedItem);
        });
      }
    

    3- to undo delete item just update that item id so that Dismissible widget has unique id always

    setState(() {
    deletedItem.uniqueId=uuid.v1();
    });
    

提交回复
热议问题