store a list of data to be used in other screens with cubit bloc

26 Views Asked by At

i am building a cart using cubit bloc: when the client chooses the product from the products page, I send the data to the cubit and save it in a list, but the problem is that I can not store it to be shown in the cart page, so my question is what is the best solution to save the cart items using cubit and be access easily in other screens

here is my cubit

 List<CartModal> myCartSlider = [];
  List<CartModal> cartListCubitFunc(CartModal cartModal) {
    emit(CartLoaded());
    emit(CartStoreState(cartList: cartModal));
    myCartSlider.add(cartModal);
    return myCartSlider;
  }

cubit state

class CartStoreState extends CartState {
  //TestModal is the modal we created
  final CartModal cartList;

  CartStoreState({required this.cartList});
}

the code of sending the data to cubit

              cartCubit!.cartListCubitFunc(
                      CartModal(
                        id: widget.productInfo['id'],
                        storeId: 2,
                        storeName: widget.productInfo['description'],
                        mainPriceId: mainPrice ?? "0",
                        addions: selectedAddionsList,
                      ),
                    );
0

There are 0 best solutions below