Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

flutter - initState没有被调用(initState not getting called)

I open PageB from PageA using this code

(我使用此代码从PageA打开PageB)

 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.

(在pageB中,当我按后退设备按钮时,它将返回到pageA,但是没有调用initState中的initState。)

Why?

(为什么?)

I want it call a function once it is back from pageB.

(我希望它从pageB返回时调用一个函数。)

  ask by John Joe translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can call PageA from PageB like this,

(您可以像这样从PageB调用PageA ,)

Navigator.of(context).pushReplacementNamed('PageA');
OR
Navigator.of(context).pushNamedAndRemoveUntil('PageA', (Route<dynamic> route) => false);

I have found an interesting blog about navigators

(我发现了一个有关导航员的有趣博客)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...