我在对话框中有一个删除按钮,单击该按钮可调用此方法:
await Firestore.instance.collection("Accessories").document(orderId).delete()
Am声明一个全局变量 称为订单
List<OrdersModel> orders = List<OrdersModel>();
am使用此方法初始化列表
Future<List<OrdersModel>> getOrdersList()async{
if(isActive){
await OrdersApi().getAllOrders(widget.user.uid,'Active').then((v){
setState(() {
orders = v;
});
});
return orders;
}else{
await OrdersApi().getAllOrders(widget.user.uid,'Completed').then((v){
setState(() {
orders = v;
});
});
return orders;
}
}
并使用streambuilder显示列表视图 使用这个:
getListOfOrders(){
return StreamBuilder<List<OrdersModel>>(
stream: getOrdersList().asStream(),
builder: (context, snapshot) {
if(snapshot.hasData == false ){
return Expanded(
child: ListView.builder(
scrollDirection: Axis.vertical,
itemCount: 10,
itemBuilder: (context,index){
return Shimmer.fromColors(
baseColor: Color(0xFFB5B5B5),
highlightColor: Color(0xFF707070),
child: Padding(padding: EdgeInsets.only(bottom: 1)
,
child: getOrderListItem("","","","",""),
),
);
}),
);
}
return Expanded(
child: ListView.builder(
scrollDirection: Axis.vertical,
itemCount: snapshot.data.length,
itemBuilder: (context,index){
retur Padding(padding: EdgeInsets.only(bottom: 1)
,
child: getOrderListItem(snapshot.data[index].orderType,snapshot.data[index].status,snapshot.data[index].date,snapshot.data[index].time,snapshot.data[index].orderId),
),
);
});
}
);
}
我正在将未来称为流,以听取更改,但是单击删除按钮时,该文档已在Firestore中删除,但仍保留在列表视图中,因此未更新,我不想强制对其进行更新。