Home > other >  Which is called first in Flutter StatefulWidget or the State class?
Which is called first in Flutter StatefulWidget or the State class?

Time:10-03

I am new to the Flutter world and haven't built any real project in any other programming language.

I am trying to understand the flutter StatefulWidget and I was going through an article (read it here), and got stuck at the below code.

class MyWidget extends StatefulWidget {
  @override
  _MyWidgetState createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        const Text("Hello, "),
        const Text("World"),
      ],
    );
  }
}

I am not able to figure out which class is calling the other class first!.

The MyWidget class is overriding the _MyWidgetState class,

class MyWidget extends StatefulWidget {
  @override
  _MyWidgetState createState() => _MyWidgetState();
}

which eventually extends the State class,

class _MyWidgetState extends State<MyWidget> {
  @override

and here the state MyWidget is itself a class!

Who is calling whom? Any reference to some documentation would be appreciated

  • Related