Denis Rudenko
Denis Rudenko

Reputation: 734

How to dismiss flutter dismissable widget programmatically?

Is it possible to dismiss dismissable programmatically? Not by swipe, but by let's say button click. The only thing that comes in mind is imitating gesture event with a certain velocity, but this sounds horribly wrong.

Upvotes: 26

Views: 2505

Answers (2)

Jannie Theunissen
Jannie Theunissen

Reputation: 30114

How about considering an AnimatedList instead.

A scrolling container that animates items when they are inserted or removed. This widget is similar to one created by ListView.builder.

Upvotes: 2

Kumar Lokesh Rathod
Kumar Lokesh Rathod

Reputation: 705

Please try this.

key: Key(UniqueKey().toString()), 

2nd Way

onDismissed: (DismissDirection direction) { dismissViewList(ObjecClass); }

And function is :

dismissViewList(ObjecClass) {
    if (_personList.contains(ObjecClass)) {
    //_personList is list of ObjecClass shown in ListView
      setState(() {
        _personList.remove(ObjecClass);
      });
    }
}

Upvotes: -3

Related Questions