1

I have a StatefulWidget InfoWidget and I want to make sure it always has a key. I'm not able to provide a default value because it has to be constant. When I try to create a GlobalKey in the super constructor call I get a lot of [ERROR] { exception: Null check operator used on a null value errors in the app (everytime I want to access the currentContext key.currentContext!...)

InfoWidget(
  {required this.child,
  Key? key,
  : super(key: key ?? GlobalKey<InfoWidgetState>());

How is it possible for the key to be Null?

0 Answers0