A dismissed Dismissible widget is still part of the tree

Hi,

I’m working through the chapter 6’s adding Dismissible widget part.

I can swipe to delete and it works fine. But if I tap on the + button right after, the app stop at the following exception

A dismissed Dismissible widget is still part of the tree.

I copied the code of the grocery_list_screen.dart from the final solution to mine and tried again but came across the same error.

I’d appreciate any guidance on how to fix this. I’m running the app in Flutter 2.5.3.

Thanks!

@vguzzi any suggestions?

@isuru

Can you please double check if you included a key?
You could also try upgrading the package to see if that works!
Or share your repo and i’ll have a quick look!

return Dismissible(
            // 6
            key: Key(item.id),
            // 7
            direction: DismissDirection.endToStart,
            // 8
            background: Container(
              color: Colors.red,
              alignment: Alignment.centerRight,
              child: const Icon(
                Icons.delete_forever,
                color: Colors.white,
                size: 50.0,
              ),
            ),

Hi @jomoka, I upgraded the provider package but no luck. I pushed my repo to my Github. Please check the below link.

https://github.com/Isuru-Nanayakkara/fooderlich-issue

You are missing the function call for notifyListeners() in the deleteItem function body.

File: grocery_manager.dart

2 Likes

@lauragales Oh! Thank you. :pray:

1 Like