Bloc: mysterious bug

Created on 13 Nov 2019  路  6Comments  路  Source: felangel/bloc

Hello. I am having a really really weird bug in a project and I was able to replicate into a simpler project. Basically, when changing screen (with maintainState = false) one bloc is still saved.. so I get two instances of the same bloc triggering BlocBuilder twice and considerably slowing down my project!

I'm not even sure if I explained correctly (therefore, mysterious bug!), but here is a sample, and in that sample, when you run, you should tap to change screen and tap to update the counter.

You should see:

I/flutter (25496): BLOC CHANGED V: 7 INDEX: 1
I/flutter (25496): BLOC CHANGED V: 7 INDEX: 5

Which means both bloc 1 and 5 are awake. I don't know if this is a common bug or etc, but I don't even know what to search. Thanks!

flutter_counter.zip

question waiting for response

Most helpful comment

Uh, thanks!
image
Ok... I thought maintainState = false was supposed to do this. PushReplacement doesn't keep anything, push keeps everything, push with maintainstate = false only keeps the first one. Really tricky.

All 6 comments

Hi @bernaferrari 馃憢
Thanks for opening an issue!

Are you able to create a gist or github repo instead of a zip? Thanks! 馃憤

I am, but do you really want that? It is almost a one-file project. Everything else is just so you can build it.

yeah if you can just share the one file as a gist it would be great, thanks!

@bernaferrari when you use Navigator.push it does not remove the underlying widget. This is expected behavior and it doesn't have anything to do with the bloc library. If you want to dispose the underlying widget when you push then you can use pushReplacement. Let me know if that helps 馃憤

Uh, thanks!
image
Ok... I thought maintainState = false was supposed to do this. PushReplacement doesn't keep anything, push keeps everything, push with maintainstate = false only keeps the first one. Really tricky.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rsnider19 picture rsnider19  路  3Comments

frankrod picture frankrod  路  3Comments

ricktotec picture ricktotec  路  3Comments

hivesey picture hivesey  路  3Comments

nhwilly picture nhwilly  路  3Comments