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.
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.
Answer leading: IconButton( onPressed: () { widget. removeFunc(widget. index); }, Source: Stackoverflow.com.
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.
Please try this.I provided UniqueKey as key to Dismissible widget, and it worked just fine.
key: UniqueKey(),
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With