Closed rrifafauzikomara closed 3 years ago
Hi Rifat,
initState() method only runs once i.e. at the beginning of your StatefulWidget. I don't see a reason in your above code, why you want to run the initState() method again. I fail to understand what exactly you're trying to accomplish. I suggest, please provide me with your WhatsApp contact, so that I can try to understand your requirement and assist you further.
Regards Mujtaba
Hi @imujtaba8488
Yeah I know that initState()
method only runs once when the StatefulWidget
is run. But the main reason why I need to execute initState()
from back
it's because I have a function on that like this:
initState() {
if (isFromEdit) {
// my function to select the data from local database
}
}
And then on the next
button I also have a function to save
data to the local database. So, If I go from Page 1
to Page 2
, it's mean will save data in the Page 1
to the local database, and then when I back
from the Page 2
to the Page 1
, it's should execute initState
because I have a function to fetch data and then the data should showed on the widget on build
method.
I believe that is in no way related to an issue with the im_stepper, hence closing it. However, as a workaround to your problem, I suggest moving the isFromEdit
to didUpdateDependency()
/didUpdateWidget()
or thebuild()
depending upon your requirement. However, moving to didUpdateDependency()
/build()
might be expensive, since they are called frequently/randomly by the Flutter engine.
I have 5 Screen (Page 1, Page 2, Page 3, Page 4, Page 5) and Main Screen (This is the root for handler stepper).
And then I have flowed like this (
next
):Page 1 -> Page 2 -> Page 3 -> Page 4 -> Page 5
=> This is will execute / run / callinitState
method.But how if we
back
fromPage 5
toPage 1
?Page 5 -> Page 4 -> Page 3 -> Page 2 -> Page 1
=> TheinitState
method is not run again fromback
.Sample Code: