Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:hive/hive.dart';
- @HiveType(typeId: 1)
- class Product {
- @HiveField(0)
- final int id;
- @HiveField(1)
- final String name;
- @HiveField(2)
- final String description;
- @HiveField(3)
- final double size;
- @HiveField(4)
- final String sizeUnit;
- @HiveField(5)
- final double price;
- @HiveField(6)
- final bool byWeight;
- @HiveField(7)
- final int quantity;
- @HiveField(8)
- final String imageStr;
- @HiveField(9)
- final int category;
- @HiveField(10)
- int _cartQuantity = 0;
- Product(this.id, this.name, this.description, this.size, this.sizeUnit,
- this.price, this.byWeight, this.quantity, this.imageStr, this.category);
- factory Product.fromJson(Map<String, dynamic> json) {
- return Product(
- json['Id'],
- json['Name'],
- json['Description'],
- json['Size'] is int ? (json['Size'] as int).toDouble() : json['Size'],
- json['Size_Unit'],
- json['Price'] is int
- ? (json['Price'] as int).toDouble()
- : json['Price'],
- json['ByWeight'] as int != 0,
- json['Quantity'],
- json['Image'],
- json['Category']);
- }
- void increaseQuantity() {
- if (_cartQuantity < quantity) {
- ++_cartQuantity;
- }
- }
- void decreaseQuantity() {
- if (_cartQuantity > 0) {
- --_cartQuantity;
- }
- }
- int getCartQuantity() => _cartQuantity;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement