title: Bloc counter for shopping cart
body: <p>I am trying to build a shopping cart using the bloc pattern as this my first app in flutter as well as using bloc. my problem is that I am trying to get the stream of an int each time the user add the product to the cart. but it seems that I am using the sink and stream wrong but I don't know exactly where </p>
  
  <p><strong>ItemCounterBloc</strong></p>
  
  <pre><code>  final _itemCounterSubject = BehaviorSubject&lt;int&gt;(seedValue: 0);
    final _cartItemsController = StreamController&lt;List&lt;CartItem&gt;&gt;();
    int count = 0;
  
  
    ItemCounterBloc(Item item){
  
      _cartItemsController.stream
      .map((list) =&gt; list.any((cartItem)=&gt; cartItem.item == item))
      .listen((increment){
        count += 1;
        _itemCounterSubject.add(count);
      });
  
  
    }
    Sink&lt;List&lt;CartItem&gt;&gt; get cartItems =&gt; _cartItemsController.sink;
  
    ValueObservable&lt;int&gt; get isInCart =&gt; _itemCounterSubject.stream.distinct().shareValue(seedValue: 0);
  
    void dispose(){
      _cartItemsController.close();
      _itemCounterSubject.close();
    }
  }
  </code></pre>
  
  <p><strong>Counter</strong></p>
  
  <pre><code>StreamBuilder&lt;int&gt;(
              stream: _bloc.isInCart,
              initialData:0,
              builder: (context, snapshot) =&gt; Text('${snapshot.data}')
  </code></pre>
  
  <p>Also I have another bloc for adding items to the cart.</p>