Duplicate GlobalKey detected in widget tree

前端 未结 10 1210
孤街浪徒
孤街浪徒 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:45

    Thanks to Gunter's commments, I determined that this is because the Screens are not being properly disposed.

    Flutter's pushReplacement makes a call to Route.dispose which will ultimately dispose the screen.

    I am still unsure as to this comes into play:

    widget must be inserted into the new location in the same animation frame

    I'm not sure what situation would benefit from such trickery. However, my problem is solved. I just need to make a call to pop or replace.

    Here are the available options:

    • Use push from A to B and just Navigator.pop from B
    • Use pushReplacement from A to B and from B to A

    I've recently started playing with Fluro for routing and there are a few more ways to to handle these situations (Note the optional argument replace):

    • Use router.navigateTo(context, route, replace: false) from A to B and Navigator.pop from B
    • Use router.navigateTo(context, route, replace: true) from A to B the same from B to A (the key is replace: true)

提交回复
热议问题