Skip to content

Commit

Permalink
README.md updated and models added.
Browse files Browse the repository at this point in the history
  • Loading branch information
BBarisKilic committed Mar 18, 2021
1 parent 208f76d commit bcd2070
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

An app that uses 'Business Logic Component' design pattern and bloc state management.

## Through this project, I've learned:

- bloc design pattern and state management.
- singleton and factory design pattern.
-
25 changes: 25 additions & 0 deletions lib/data/cart_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:bloc_shopping/models/cart_item.dart';

class CartService {
static List<CartItem> cartItems = List<CartItem>();

static CartService _singleton = CartService._internal();

factory CartService() {
return _singleton;
}

CartService._internal();

static void addToCart(CartItem cartItem) {
cartItems.add(cartItem);
}

static void removeFromCart(CartItem cartItem) {
cartItems.remove(cartItem);
}

static List<CartItem> getCart() {
return cartItems;
}
}
20 changes: 20 additions & 0 deletions lib/data/product_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:bloc_shopping/models/product.dart';

class ProductService {
static List<Product> products = new List<Product>();

static ProductService _singleton = ProductService._internal();

factory ProductService() {
return _singleton;
}

ProductService._internal();

static List<Product> getAll() {
products.add(Product(1, "Acer Laptop", 6000));
products.add(Product(2, "MSI Laptop", 9000));
products.add(Product(3, "Asus Laptop", 8000));
return products;
}
}
8 changes: 8 additions & 0 deletions lib/models/cart_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:bloc_shopping/models/product.dart';

class CartItem {
Product product;
int quantity;

CartItem(this.product, this.quantity);
}
7 changes: 7 additions & 0 deletions lib/models/product.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Product {
int id;
String name;
double price;

Product(this.id, this.name, this.price);
}

0 comments on commit bcd2070

Please sign in to comment.