title: Prevent value in bloc from resetting
body: <p>I have 2 screens, 1 product screen and 1 cart screen. The product screen just displays all the product and when the user clicks add to cart, it will fire the AddToCart event. The problem is I keep getting 'Cart is empty.' and the cart variable in <em>cart bloc</em> keeps resetting to [] when i switch back and forth the product and cart screen.</p>
  <p><strong>Main screen</strong></p>
  <pre><code>MultiBlocProvider(
      providers: [
        BlocProvider&lt;ProductBloc&gt;(
          create: (BuildContext context) =&gt; ProductBloc()..add(FetchProduct()),
        ),
        BlocProvider&lt;CartBloc&gt;(
          create: (BuildContext context) =&gt; CartBloc()..add(FetchCart()),
        ),
      ],
  )
  </code></pre>
  <p><strong>Cart State</strong></p>
  <pre><code>abstract class CartState extends Equatable {
    const CartState();
    @override
    List&lt;Object&gt; get props =&gt; [];
  }
  class CartInitial extends CartState {}
  class CartLoading extends CartState {}
  class CartSuccess extends CartState {
    final List&lt;ProductModel&gt; carts;
    const CartSuccess(this.carts);
    @override
    List&lt;Object&gt; get props =&gt; [carts];
  }
  class CartFailed extends CartState {}
  </code></pre>
  <p><strong>Cart Event</strong></p>
  <pre><code>abstract class CartEvent extends Equatable {
    const CartEvent();
    @override
    List&lt;Object&gt; get props =&gt; [];
  }
  class FetchCart extends CartEvent {}
  class AddToCart extends CartEvent {
    final ProductModel product;
    const AddToCart(this.product);
    @override
    List&lt;Object&gt; get props =&gt; [product];
  }
  class RemoveFromCart extends CartEvent {
    final ProductModel product;
    const RemoveFromCart(this.product);
    @override
    List&lt;Object&gt; get props =&gt; [product];
  }
  </code></pre>
  <p><strong>Cart Bloc</strong></p>
  <pre><code>class CartBloc extends Bloc&lt;CartEvent, CartState&gt; {
    CartBloc() : super(CartInitial());
  
    List&lt;ProductModel&gt; carts = []; // always resets
  
    Stream&lt;CartState&gt; mapEventToState(CartEvent event) async* {
  
      print(carts);
  
      if(event is FetchCart){
          yield CartSuccess(carts);
          print(carts.length);
      }
  
      if(event is AddToCart){
        try{
          carts.add(event.product);
          yield CartSuccess(carts);
          print(carts.length);
        }catch(e){
          yield CartFailed();
          print(e);
        }
      }
  
      if(event is RemoveFromCart){
        try{
          carts.remove(event.product);
          yield CartSuccess(carts);
        }catch(e){
          yield CartFailed();
          print(e);
        }
      }
  
    }
  }
  </code></pre>
  <p><strong>Cart Screen</strong></p>
  <pre><code>  Widget build(BuildContext context) {
      return Container(
        child: Padding(
          padding: EdgeInsets.all(10.0),
          child: BlocBuilder&lt;CartBloc, CartState&gt;(
            builder: (context, state) {
              if(state is CartInitial){
                print('CartInitial');
                return buildLoadingWidget();
              }
              if(state is CartSuccess){
                print('CartSuccess');
                if(state.carts.length == 0)
                  return Center(
                    child: Text('Cart is empty.',style: TextStyle(color: Colors.white,)
                  ));
                else
                  return _buildProductListWidget(state.carts);
              }
              if(state is CartFailed){
                print('CartFailed');
                return Center(
                  child: Text('Something went wrong'),
                );
              }
              return buildLoadingWidget();
            }
          )
        ),
      );
    }
  </code></pre>