You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clicks "go to company" and then clicks "next company", you will see
I/flutter ( 8026): The following assertion was thrown building Company():
I/flutter ( 8026): Multiple widgets used the same GlobalKey.
I/flutter ( 8026): The key [LabeledGlobalKey<ScaffoldState>#33415169] was used by multiple widgets. The parents of
I/flutter ( 8026): those widgets were different widgets that both had the following description:
I/flutter ( 8026): Company()
I/flutter ( 8026): A GlobalKey can only be specified on one widget at a time in the widget tree.
It seems that the popped route did not remove the global key from the widget tree.
When you pop a route, it animates away. While this is happening, the old route and the new route are both on the screen at the same time, and cannot share a global key.
The issue is resolved if you make _scaffoldKey non-static. I was wondering is this a proper way to assign a global key to the StatelessWidget or State<T> for StatefulWidget?
classCompanyStateextendsState<Company> {
final _scaffoldKey =newGlobalKey<ScaffoldState>();
/// use _scaffoldKey to show snackbar...
}
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
eseidelGoogle commentedon May 18, 2017
@Hixie would know.
Hixie commentedon May 18, 2017
When you pop a route, it animates away. While this is happening, the old route and the new route are both on the screen at the same time, and cannot share a global key.
123qws commentedon May 18, 2017
Thanks @Hixie !
The issue is resolved if you make
_scaffoldKeynon-static. I was wondering is this a proper way to assign a global key to theStatelessWidgetorState<T>for StatefulWidget?Hixie commentedon May 18, 2017
Usually I just skip using the key and use the Builder pattern instead. See the second code snippet here:
https://docs.flutter.io/flutter/material/Scaffold/of.html
123qws commentedon May 18, 2017
Thanks! Builder pattern looks good!
Roll engine to 6e6de94
Roll engine to 6e6de94 (#40394)
Roll engine 7ea9884..1b63444 (91 commits 🔥🔥🔥) (#40442)
Roll engine to 6e6de94 (flutter#40394)
Roll engine 7ea9884..1b63444 (91 commits 🔥🔥🔥) (flutter#40442)
github-actions commentedon Sep 4, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.