flutter-demo/lib/models/item_category_model.dart
LingandRX b53fe04e54 feat(category): 添加分类功能
- 新增分类列表页面和分类详情页面
- 实现分类数据的加载、刷新和展示
- 添加分类相关的数据模型、提供者和仓库
- 优化数据库操作,统一表名和查询条件
2025-05-08 21:06:52 +08:00

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,
);
}
}