Skip to content

Commit

Permalink
task: provider data adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Atuoha committed Oct 10, 2022
1 parent b0e9a0f commit 0401abc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/models/cart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class CartItem {
final String prodId;
final String prodName;
final String prodImgUrl;
double prodPrice;
final double prodPrice;
double totalPrice;
int quantity;

Expand Down
2 changes: 2 additions & 0 deletions lib/models/order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ class Order {
final String prodName;
final String prodImg;
final int quantity;
final int price;

Order({
required this.id,
required this.prodId,
required this.prodName,
required this.prodImg,
required this.quantity,
required this.price,
});
}
15 changes: 15 additions & 0 deletions lib/providers/cart.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:multivendor_shop/models/cart.dart';

class CartData extends ChangeNotifier {
var totalPrice = 0.0;
Expand All @@ -15,6 +16,20 @@ class CartData extends ChangeNotifier {
notifyListeners();
}

void addToCart(CartItem cart) {
CartItem item = CartItem(
id: DateTime.now().toString(),
prodId: cart.prodId,
prodName: cart.prodName,
prodPrice: cart.prodPrice,
prodImgUrl: cart.prodImgUrl,
totalPrice: cart.totalPrice,
);

_cartItems.add(item);
notifyListeners();
}

void removeFromCart(String id) {
var cartItem = _cartItems.firstWhere((item) => item.id == id);
_cartItems.remove(cartItem);
Expand Down
15 changes: 15 additions & 0 deletions lib/providers/order.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import 'package:flutter/material.dart';
import 'package:multivendor_shop/models/order.dart';

class OrderData extends ChangeNotifier {
var totalPrice = 0.0;

void addToOrder(Order order) {
Order item = Order(
id: DateTime.now().toString(),
prodId: order.prodId,
prodName: order.prodName,
price: order.price,
quantity: order.quantity,
prodImg: order.prodImg,
);

_orderItems.add(item);
notifyListeners();
}

void removeFromOrder(String id) {
var orderItem = _orderItems.firstWhere((item) => item.id == id);
_orderItems.remove(orderItem);
Expand Down

0 comments on commit 0401abc

Please sign in to comment.