class ItemCategory { final int? id; final String name; final String? description; final String? createdAt; final String? updatedAt; ItemCategory({ this.id, required this.name, this.description, this.createdAt, this.updatedAt, }); // fromMap — 数据库 map -> Dart 对象 factory ItemCategory.fromMap(Map map) { return ItemCategory( id: map['id'] as int?, name: map['name'] as String, description: map['description'] as String?, createdAt: map['created_at'] as String?, updatedAt: map['updated_at'] as String?, ); } // toMap — Dart 对象 -> 数据库 map Map toMap() { return { 'id': id, 'name': name, 'description': description, 'created_at': createdAt, 'updated_at': updatedAt, }; } // copyWith — 方便局部更新 ItemCategory copyWith({ int? id, String? name, String? description, String? createdAt, String? updatedAt, }) { return ItemCategory( id: id ?? this.id, name: name ?? this.name, description: description ?? this.description, createdAt: createdAt ?? this.createdAt, updatedAt: updatedAt ?? this.updatedAt, ); } }