【发布时间】:2023-03-31 08:53:02
【问题描述】:
我想使用 navigator.pop 将值从第二页传递到第一页并使用 initstate 中的新值刷新或重新加载我的第一页或任何其他解决方法?
我能够在第一页中获取这些值,但无法使用 initstate 中的新值刷新或重新加载页面,我想在 API 中传递新数据 n 获取响应...
有什么帮助吗?
我正在从这里重定向到列表页面...
getBrand(BuildContext context) async {
tempBrand = await Navigator.push(context,
MaterialPageRoute(builder: (context) => BrandList(widget.subCatID)));
selectedBrand = tempBrand.name;
selectedBrandID = tempBrand.id;
}
现在我在 navigator.pop 中传递这些值
在此处获取价值并返回第一页。
Container(
padding: EdgeInsets.all(10),
child: ListView.separated(
separatorBuilder: (context, index) =>
Divider(color: Color(0xffcccccc)),
itemCount: prodBrands.length,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
child: InkWell(
onTap: () {
tempProdBrand = ProdBrandListModel.Message(
id: prodBrands[index].id,
name: prodBrands[index].name,
);
Navigator.pop(context, tempProdBrand);
},
child: Container(
child: Text(prodBrands[index].name),
padding: EdgeInsets.all(10.0),
),
),
);
}),
)
想在这里使用新值...
submitProduct() {
api
.newbiz(
selectedBrandID,
)
.then((response) {
setState(() {
productID = response.message;
});
});
setState(() {});
}
当我使用 pop 函数中传递的新值返回第一页时,只想从 initstate 或任何其他方式刷新我的页面。
【问题讨论】:
-
你必须在从
Navigator.push()返回后重建你的第一页——例如通过调用State#setState()方法 -
请添加代码示例?我已经尝试过,但是从第二页(弹回第一页)开始……第一页甚至不接受 setstate..
-
这是 3 分钟的谷歌搜索:stackoverflow.com/a/49806432/2252830
-
感谢链接
标签: android dart flutter navigator