如何解决在navigator.pop之后无法更新状态
我仍在学习颤动,但遇到了问题。我有2个屏幕,其中一个是ProductList,另一个是ProductAdd。问题是当用户单击添加按钮程序时,导航到ProductAdd。用户输入一些信息,然后单击“确定”。 ProductAdd做了一些sqflite的工作,并调用了navigation.pop(),但是用户返回首页后状态没有改变,但是当我重新加载页面时状态会改变。 这是产品清单。(productCount是当我要调用navigation.pop时要更新的清单)
ListView buildProductList() {
return ListView.builder(
itemCount: productCount,itemBuilder: (BuildContext context,int position){
return Card(
color: Colors.cyan,elevation: 2.0,child: ListTile(
leading: CircleAvatar(backgroundColor: Colors.black12,child: Text("p"),),title: Text(this.products[position].name),subtitle: Text(this.products[position].description),onTap: (){},);
});
}
void gotoProductAdd() async {
var result = await Navigator.push(context,MaterialPageRoute(builder: (context)=>ProductAdd()));
getProducts();
}
void getProducts() async{
var productsFuture = dbHelper.getProducts();
//data is the data coming from sqflite db
productsFuture.then((data){
this.products = data;
productCount = data.length;
});
}
}
这里是ProductAdd(执行了navigator.pop()的地方)
void addProduct() async{
var result = await
dbHelper.insert(Product(name:txtName.text,description:txtDescription.text,unitPrice:double.tryParse(txtUnitPrice.text)));
Navigator.pop(context,true);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。