我有2页PAGE A和PAGEB。我浏览PAGE A-> PAGE B并编辑一些数据或切换设置。现在,我要浏览PAGE B-> PAGE A表格,以及要在导航器pop方法上发送的参数。现在我的问题是:
如何在PAGE A中访问这些参数?
Navigator.pop(context, this.selectedEquipmentId);
最佳答案
实际上,您在结束PageA时必须返回一些内容。我用一个带有弹出窗口的示例来选择我最近制作的地址,如果不是弹出窗口,则此工作完全相同。
Future<PlacesDetailsResponse> showAdressPicker({@required BuildContext context}) async {
assert(context != null);
return await showDialog<PlacesDetailsResponse>(
context: context,
builder: (BuildContext context) => AdressPickerComponent(),
);
}
您可以从Navigator.pop(...)发送结果,并从PageA获取结果
Navigator.pop(context, result)
只需在结果中放入您想要的任何内容即可(在这里,我创建了一个名为PlacesDetailsResponse的类,使用您的类,或者只是Int,String ...)。
现在在pageA中,当您调用此命令时
showAdressPicker(context: context).then((PlacesDetailsResponse value) {
//do whatever you want here
// this fires when PageB call previous to PageA
});