What is the difference between initState and a class constructor in Flutter?

The difference is (in the context of creating a State object) which has the initState() method:

  • constructor simply create a new State instance

  • initState() is called after the object is created and at this point
    you have access to the BuildContext or the StatefulWidget to which the State is attached to, respectively using the context and the widget properties. At this point the State is already mounted.

Reference State: https://api.flutter.dev/flutter/widgets/State-class.html

Reference mounted State: https://api.flutter.dev/flutter/widgets/State/mounted.html

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)