Duplicate GlobalKey detected in widget tree

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

    Best way to solve that, which worked for me:

    class _HomeScreenState extends State {
       GlobalKey _homeKey = GlobalKey(debugLabel: '_homeScreenkey');
       @override
       Widget build(BuildContext context) {
         return Container(
           key: _homeKey,
         );
       }
    }
    

提交回复
热议问题