Duplicate GlobalKey detected in widget tree error when using global keys #249
-
Hi @csells , Great package! However I'm struggling with an issue and I am not sure how to deal with it. When I'm using the same scaffold for two screens, when I move from screen A to screen B using this: I assume the previous screen is not fully disposed or so. Is there a solution for this?
Thank you, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @raduungurean 👋, It seems you have registered the If that is the case, you can fix it by changing the dependency registration from singleton to factory. But generally speaking, I don't see the necessity of using Hope that helps! |
Beta Was this translation helpful? Give feedback.
Hi @raduungurean 👋,
It seems you have registered the
GlobalKey<ScaffoldState>
as a singleton inGetIt
. So whenever you are trying to use the global key,GetIt
will return the same global key and end up with multiple widgets trying to use the same global key somewhere in your widget tree.If that is the case, you can fix it by changing the dependency registration from singleton to factory. But generally speaking, I don't see the necessity of using
GetIt
for this case in the first place. So I think it is better to put the key somewhere with the widget that is using it.Hope that helps!