0.9 C
New York
Friday, February 3, 2023

Flutter: A dismissed Dismissible widget is still part of the tree

This article shows you how to solve a problem when working with the Dismissible widget in Flutter.

The Problem

When working with the Dismissible widget in Flutter, you may fall into this error:Advertisements

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.

Why does it happen?

The reason is that the value passed to the key property isn’t unique or related to the index of each item in a list. These two settings get me in trouble and you should get rid of them:

key: Key(index),
key: ValueKey(index),

After removing an item from a list, the list will shift the positions of the items and the Dismissible widget cannot recognize the removal of the item.


The solution is quite simple and all you need to do is set the key property to UniqueKey(), like this:

key: UniqueKey(),

AdvertisementsThat’s it. Hope this helps.

Further reading:

You can also check out our Flutter category page or Dart category page for the latest tutorials and examples.

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles