如何解决Bloc Stream在继承的页面中未更新
我正在开发一个应用程序,其中有主页,该页面由选项卡组成,并且其中一个选项卡页面具有另一个组件页面,即 ProductCardPage 。现在我有了流课程
class CartBloc {
final _cartController = StreamController<List<Cart>>.broadcast();
get cart => _cartController.stream;
getCartItems(int userID) async {
if (userID != null) {
_cartController.sink.add(await DBProvider.db.getAllItems(userID));
}
}
我想从 streambuilder 处获取我在HomePage上获取的BadgeIcon的数据
return StreamBuilder( stream: bloc.cart,// pass our Stream getter here
initialData: [],//when nothing is pushed to the stream yes,I assume an empty list
builder: (context,snapshot) {
Icon(Icons.shopping_cart,size: 26.0,color: Theme.of(context).primaryColor),itemCount: (snapshot.hasData) ? snapshot.data.length : 0,
它第一次显示正确的数据,然后在添加或更新产品后不更新流生成器。
Future<int> add(Cart cart,int userID) async {
// cancelNotification();
// scheduleNotification({"data":{"title": "title goes here","body": "body goes here","content": '{"data":{"title": "title goes here","body": "body goes here"}}'}});
int id = await DBProvider.db.newItem(cart);
_cartController.sink.add(await DBProvider.db.getAllItems(userID));
如何在此层次结构中重建流生成器。
预先感谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。