本文介绍了弹出第二页后触发FirstPage的setState方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

myapp中有两个页面,分别是FirstPage和SecondPage.

I have two pages in myapp namely FirstPage and SecondPage.

基本上,FirstPage小部件显示带有项目列表的ListView,而SecondPage小部件是我可以在列表中添加/删除项目的位置.

Basically, FirstPage widget displays a ListView with a list of items while SecondPage widget is where I can add/delete items to the list.

我可以通过以下方式导航到SecondPage:

I can navigate to the SecondPage by:

Navigator.of(context).pushNamed("/SecondPage");

我也可以使用以下命令返回到第一页:

And also I can go back to the FirstPage by using:

Navigator.of(context).pop();

我的问题是,在弹出SecondPage以便更新FirstPage的ListView之后,我不知道如何触发FirstPage小部件的setState方法.

My problem is I can't figure out how am I going to trigger the setState method of FirstPage widget after popping the SecondPage so that the FirstPage's ListView is updated.

任何提示,我将不胜感激.

I would appreciate any hint.

推荐答案

每当我们推动时,我们都会获得未来,我们可以利用这一未来来触发setState

Whenever we push, we will get a future, we can use that future to trigger the setState

Future pushNamed = Navigator.of(context).pushNamed("/SecondPage");
pushNamed.then((_)=> setState(() {}));

此处进行引用,以将数据从secondScreen发送到firstScreen.

Refer here to send data from secondScreen to firstScreen.

这篇关于弹出第二页后触发FirstPage的setState方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 13:26