-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
208f76d
commit bcd2070
Showing
5 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |