当用户单击返回或我在第二个屏幕中使用Navigator.pop()
时,我正在尝试运行某种方法。
我有两个屏幕。
编辑后,我将用户弹出到第一秒。现在,在第一个屏幕中,我使用SharedPreference
。但是,当用户返回第一个屏幕时,我需要重新运行一种方法。我怎样才能做到这一点?
答案 0 :(得分:1)
从Edit
屏幕导航到Settings
屏幕时,请使用此屏幕(在Settings
屏幕内部)
Navigator.pushNamed(context, "/editScreen").then((_) {
// you have come back to your Settings screen
yourSharedPreferenceCode();
});
如果您只想在Edit
屏幕上发生的某些事件上运行此代码,则可以在pop
屏幕内使用Edit
方法,例如
Navigator.pop(context, true); // pass true value
以上代码应为:
Navigator.pushNamed(context, "/editScreen").then((value) {
if (value) // if true and you have come back to your Settings screen
yourSharedPreferenceCode();
});