From 3754935eb86ad716552aa9f9fa287931daf9ddf4 Mon Sep 17 00:00:00 2001 From: BBarisKilic Date: Fri, 19 Mar 2021 03:20:31 +0300 Subject: [PATCH] blocs added. --- lib/blocs/cart_bloc.dart | 26 ++++++++++++++++++++++++++ lib/blocs/product_bloc.dart | 16 ++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/blocs/cart_bloc.dart create mode 100644 lib/blocs/product_bloc.dart diff --git a/lib/blocs/cart_bloc.dart b/lib/blocs/cart_bloc.dart new file mode 100644 index 0000000..99a4596 --- /dev/null +++ b/lib/blocs/cart_bloc.dart @@ -0,0 +1,26 @@ +import 'dart:async'; + +import 'package:bloc_shopping/data/cart_service.dart'; +import 'package:bloc_shopping/models/cart_item.dart'; + +class CartBloc { + final cartStreamController = StreamController.broadcast(); + + Stream get getStream => cartStreamController.stream; + + void addToCart(CartItem cartItem) { + CartService.addToCart(cartItem); + cartStreamController.sink.add(getCart()); + } + + void removeFromCart(CartItem cartItem) { + CartService.removeFromCart(cartItem); + cartStreamController.sink.add(getCart()); + } + + List getCart() { + return CartService.getCart(); + } +} + +final cartBloc = CartBloc(); diff --git a/lib/blocs/product_bloc.dart b/lib/blocs/product_bloc.dart new file mode 100644 index 0000000..3bdabc4 --- /dev/null +++ b/lib/blocs/product_bloc.dart @@ -0,0 +1,16 @@ +import 'dart:async'; + +import 'package:bloc_shopping/data/product_service.dart'; +import 'package:bloc_shopping/models/product.dart'; + +class ProductBloc { + final productStreamController = StreamController.broadcast(); + + Stream get getStream => productStreamController.stream; + + List getAll() { + return ProductService.getAll(); + } +} + +final productBloc = ProductBloc();