Duplicate GlobalKey detected in widget tree

前端 未结 10 1188
孤街浪徒
孤街浪徒 2021-01-03 19:21

I am running into a globalKey error after I navigate from Screen A to Screen B and click a \"Cancel\" button to go back to Scree

10条回答
  •  爱一瞬间的悲伤
    2021-01-03 19:23

    In my case I wanted to use the static GlobalKey _scaffoldKey but when I used the same widget multiple times it gave this duplicate error.

    I wanted to give it a unique string and still use this scaffold state. So I ended up using:

    static GlobalObjectKey _scaffoldKey
    

    and in the initState:

    _scaffoldKey = new GlobalObjectKey(id);
    

    Edit: Actually, silly me. I just simply removed the static and made it GlobalKey again :)

提交回复
热议问题