在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 (将#修改为@)