I want to setState my buttonbar widget in the other file. What can i do? -my code is true. I have any error. Just i want true setState.- But if i write DesktopHeader.desktopHeaderKey.currentState!.setState({}), it's null returning.
class DesktopHeader extends StatefulWidget {
static GlobalKey<State> desktopHeaderKey = GlobalKey();
const DesktopHeader({Key? key}) : super(key: key);
@override
_DesktopHeaderState createState() => _DesktopHeaderState();
}
class _DesktopHeaderState extends State<DesktopHeader> {
@override
Widget build(BuildContext context) {
return butonBar();
}
Widget butonBar() { ... }
}
CodePudding user response:
When starting DesktopHeader, do you start it with key? In that:
DesktopHeader(key: DesktopHeader.desktopHeaderKey)
CodePudding user response:
you can try return type DesktopHeader class
final GlobalKey< State<DesktopHeader>>
globalKey = GlobalKey< State<DesktopHeader>>();