flutter-demo/lib/models/item_category_model.dart
LingandRX b2217ae2be feat(category): 新增分类功能并重构相关屏幕
- 新增 CategoryScreen 屏幕用于显示分类- 新增 ItemCategory 模型类用于分类数据管理
- 新增 ItemCategoryRepository 用于分类数据持久化
- 新增 item_category_table 创建分类表结构
-重构 HomeScreen 底部导航栏,增加分类选项
- 重命名相关屏幕文件,统一命名规范
- 调整 ItemScreen 以适应新增的分类功能- 更新 SQLiteHelper 以支持分类表创建和默认分类插入
- 删除 StatisticsScreen 屏幕
2025-05-07 22:52:20 +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'] 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<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,
);
}
}