Omar Shamali

initState and dispose in dart Flutter StatefulWidget: Where to put super calls?

Author: Omar Shamali
Writing Date:

In Flutter using dart language, where to put supers in each method?

Remember they need to have override tag, as follows:

void initState() {
super.initState();
}

and

@override
void dispose() {
super.dispose();
}

but if we have specific code in these methods, where to put the super calls?

for initstate, we should at the beginning of the method, like this:

@override
void initState() {
super.initState();

//here we right our code
print("all looks good");
}

for dispose, we should at the end of the method, like this:

@override
void dispose() {
//here we right our code
print("all looks good");


super.dispose();
}