Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Duplicate GlobalKey detected in widget tree error when using global keys #249

Answered by elias8
raduungurean asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @raduungurean 👋,

It seems you have registered the GlobalKey<ScaffoldState> as a singleton in GetIt. 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!

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by csells
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #243 on December 17, 2021 04:14.