Global Key - strange behaviour, could someone please explain

OK, I’m new to Flutter and trying to learn it on the side. I’m playing about with some simple widgets doing cross widget method calls.

The following class is simply a Textbox (MyTextBox) widget and a widget containing 3 buttons (MyButtonList).

The MyTextBox widget contains 3 methods which get called from the 3 buttons on MyButtonList. Straight forward stuff really.

class MyMainPage extends StatefulWidget {
MyMainPage({Key key}) : super(key: key);
State createState() => _MyMainPageState();
class _MyMainPageState extends State {
GlobalKey key = GlobalKey();
Widget build(BuildContext context) {
return ListView(children: [
key: key,
MyButtonList(parentState: key),

This works perfectly. However, if I want to move the MyTextBox widget to BELOW the MyButtonList in the listview the application crashes with “NoSuchMethodError: the getter ‘add1’ was called on null.”

It looks as though the GlobalKey has to be created and used before it can be referenced by another widget.

I then tried to initialize the MyTextBox widget using

void initState() {
key = GlobalKey();
myTextBox = new MyTextBox(key: key);
myButtonList = new MyButtonList(parentState: key);

And variations of. Adding the widget variables to the listview further down. Whatever I do I cannot seem to get the app to run if I try and put the textbox after the buttons.

Anyone any idea of what I need to do to be able to put the MyTextBox after the MyButtonList ?

This editor seems to have taken certian bits of code out? - you should still be able to get the gist of what I’m getting at though.

Thanks, Steve.