import 'package:item_tracker/screens/item_screens/item_screen.dart'; class Item { int? id; // 名称 final String name; // 分类 final int? categoryId; // 位置 final String? location; // 描述 final String? description; // 价格 final double? price; // 购买日期 final DateTime? purchaseDate; // 是否使用 final ItemIsUse? isInUse; // 数据状态 -normal -deleted final String? status; // 创建时间 final DateTime? createdAt; // 更新时间 final DateTime? updatedAt; Item({ this.id, required this.name, this.categoryId, this.location, this.description, this.price, this.purchaseDate, this.isInUse = ItemIsUse.no, this.status = 'normal', this.createdAt, this.updatedAt, }); Map toMap() { return { 'name': name, 'category_id': categoryId, 'location': location, 'description': description, 'price': price, 'purchase_date': purchaseDate, 'is_in_use': isInUse?.toInt(), 'status': status, 'created_at': createdAt, 'updated_at': updatedAt, }; } factory Item.fromMap(Map map) { return Item( id: map['id'], name: map['name'], categoryId: map['category_id'], location: map['location'], description: map['description'], price: map['price'], purchaseDate: map['purchase_date'], isInUse: map['is_in_use'] != null ? ItemIsUseX.fromInt(int.parse(map['is_in_use'].toString())) : ItemIsUse.no, status: map['status'], createdAt: map['created_at'], updatedAt: map['updated_at'], ); } }