Reputation: 2276
Should my custom initialize()
run before or after super.initState()
? Or does it not matter?
@override
void initState() {
super.initState();
initialize();
}
OR
@override
void initState() {
initialize();
super.initState();
}
Upvotes: 0
Views: 28
Reputation: 9744
According to the documentation of initState
method:
Implementations of this method should start with a call to the inherited method, as in super.initState().
So the answer is that you have to call it first. The reason in my opinion is that the inherited method is responsible for basic initialisation when the widget is inserted into to widget tree, so calling your code before super.initState()
could result in undesired behaviour.
Upvotes: 1