Advertisement
rafisbr

cart_model.dart

Jul 13th, 2021
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import 'package:shamo/models/product_model.dart';
  2.  
  3. class CartModel {
  4. int id;
  5. ProductModel product;
  6. int quantity;
  7.  
  8. CartModel({
  9. required this.id,
  10. required this.product,
  11. required this.quantity,
  12. });
  13.  
  14. factory CartModel.fromJson(Map<String, dynamic> json) {
  15. return CartModel(
  16. id: json['id'],
  17. product: ProductModel.fromJson(json['product']),
  18. quantity: json['quantity'],
  19. );
  20. }
  21.  
  22. Map<String, dynamic> toJson() {
  23. return {
  24. 'id': id,
  25. 'product': product.toJson(),
  26. 'quantity': quantity,
  27. };
  28. }
  29.  
  30. double getTotalPrice() {
  31. return product.price * quantity;
  32. }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement