initState not getting called

877 views
Skip to first unread message

Tony Seng

unread,
Dec 1, 2019, 11:17:34 AM12/1/19
to Flutter Development (flutter-dev)

I open PageB from PageA using this code

 Navigator.pushNamed(context, PageB.ROUTE);


In pageB, when I press the back device button, it will return to pageA, but the initState in PageA is not getting called. Why? I want it call a function once it is back from pageB.

Andy Greenshaw

unread,
Dec 1, 2019, 11:30:51 AM12/1/19
to Flutter Development (flutter-dev), Tony Seng
Because PageA already exists on the stack. It is not being recreated, so initState is not called again.
You could do 
 await Navigator.pushNamed(context, PageB.ROUTE);
// now here do whatever you like to update PageA (eg setState)
--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/7f157183-456e-4989-9a82-cf0a25c60c78%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages