按下后退按钮后如何刷新页面 [英] How to refresh a page after back button pressed
问题描述
我有一个列表页面。和一个添加页面。用户单击添加页面,转到新页面,在该页面中添加一些实体。然后,我弹出导航器,然后用户返回列表页面。
I have a "list page". and an add page. User clicks "add page", goes to a new page where they add some entity. Then I pop the Navigator, and user goes back to "list page".
在这一点上,我想以某种方式得到通知-也许可以回调?重写方法,我不太确定-并从数据库中重新读取信息。
At this point, I want to get notified somehow - callback maybe? override a method, I am not really sure - and re-read the information from database.
在Flutter中是否有这样的钩子?还是我应该使用另一种模式?
Is there a hook like this in Flutter? Or is there another pattern that I should use?
推荐答案
Navigator.push
方法返回Route的通用类型的未来:
The Navigator.push
method returns a future of the generic type of the Route:
Navigator.of(context)
.push(new MaterialPageRoute<String>(...))
.then((String value) {
print(value);
});
在新路线内,当您拥有所需的值时:
And inside the new route, when you have the value you need:
Navigator.of(context).pop('String');
这篇关于按下后退按钮后如何刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!