Skip to content

Commit

Permalink
blocs added.
Browse files Browse the repository at this point in the history
  • Loading branch information
BBarisKilic committed Mar 19, 2021
1 parent bcd2070 commit 3754935
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/blocs/cart_bloc.dart
Original file line number Diff line number Diff line change
@@ -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<CartItem> getCart() {
return CartService.getCart();
}
}

final cartBloc = CartBloc();
16 changes: 16 additions & 0 deletions lib/blocs/product_bloc.dart
Original file line number Diff line number Diff line change
@@ -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<Product> getAll() {
return ProductService.getAll();
}
}

final productBloc = ProductBloc();

0 comments on commit 3754935

Please sign in to comment.