Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dismissing a Dismissible with Flutter/Dart

Tags:

flutter

dart

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:

Widget build(BuildContext context) {   return new Scaffold(     key: _scaffoldKey,     appBar: new AppBar(       title: new Text(widget.title),     ),     body: new Center(       child: new ListView(         children: <Widget>[           new Dismissible(             key: personKey,             child: new Text('Dismiss Me'),             onDismissed: (DismissDirection direction) {}           )         ],       ) // end ListView     ) // end Center   ); // end return } // end build() 

After I dismiss the text box, I get the error:

A dismissed Dismissible widget is still part of the tree.

Make sure to implement the onDismissed handler and to immediately remove the Dismissible widget from the application once that handler has fired.

Digging through the Dismissible source at , I see that it checks that status of _resizeAnimation, but I'm not sure how that fits into the grand scheme of a Dismissible constructor or onDismissed handler.

like image 484
Don Boots Avatar asked Dec 10 '17 02:12

Don Boots


People also ask

How do you dismiss a widget in flutter?

This sample shows how you can use the Dismissible widget to remove list items using swipe gestures. Swipe any of the list tiles to the left or right to dismiss them from the ListView.

How do you delete a Listtile in flutter?

Answer leading: IconButton( onPressed: () { widget. removeFunc(widget. index); }, Source: Stackoverflow.com.

What is dismissible flutter?

Flutter Widget - Dismissible() Dismissible takes a child, a background, and a key, and it will detect swipe gestures and animate the child, sliding over the background.


2 Answers

Please try this.I provided UniqueKey as key to Dismissible widget, and it worked just fine.

key: UniqueKey(),  
like image 171
Salil Luley Avatar answered Sep 20 '22 13:09

Salil Luley


Make sure the values you're passing to the key parameters are unique as well. And DO NOT use the index of an item. Since after removing an item from an array, the array will shift the positions of the items, the Dismissable widget will not recognize the removal of an item.

like image 22
Mike O. Avatar answered Sep 20 '22 13:09

Mike O.