55 lines
1.2 KiB
Dart
55 lines
1.2 KiB
Dart
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<String, dynamic> map) {
|
|
return ItemCategory(
|
|
id: map['id'],
|
|
name: map['name'],
|
|
description: map['description'],
|
|
createdAt: map['created_at'],
|
|
updatedAt: map['updated_at'],
|
|
);
|
|
}
|
|
|
|
// toMap — Dart 对象 -> 数据库 map
|
|
Map<String, dynamic> 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,
|
|
);
|
|
}
|
|
}
|