问题描述
我正在开发一个应用程序,其中有主页,该页面由选项卡组成,并且其中一个选项卡页面具有另一个组件页面,即 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 (将#修改为@)