- 创建 Item 模型类,包含 toMap 和 fromMap 方法 - 新增 ItemRepository 类,负责数据库操作 - 实现 ItemScopedModel,用于状态管理 - 更新 SQLiteHelper,使用新的 item 表结构- 删除旧的 SQLiteOperation 文件
57 lines
1.2 KiB
Dart
57 lines
1.2 KiB
Dart
class Item {
|
|
int? id;
|
|
// 名称
|
|
final String name;
|
|
// 分类
|
|
final int? categoryId;
|
|
// 位置
|
|
final int? locationId;
|
|
// 描述
|
|
final String? description;
|
|
// 购买日期
|
|
final DateTime? purchaseDate;
|
|
// 是否使用
|
|
final bool isInUse;
|
|
final DateTime? createdAt;
|
|
final DateTime? updatedAt;
|
|
|
|
Item({
|
|
this.id,
|
|
required this.name,
|
|
this.categoryId,
|
|
this.locationId,
|
|
this.description,
|
|
this.purchaseDate,
|
|
this.isInUse = false,
|
|
this.createdAt,
|
|
this.updatedAt,
|
|
});
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'id': id,
|
|
'name': name,
|
|
'categoryId': categoryId,
|
|
'locationId': locationId,
|
|
'description': description,
|
|
'purchaseDate': purchaseDate,
|
|
'isInUse': isInUse,
|
|
'createdAt': createdAt,
|
|
'updatedAt': updatedAt,
|
|
};
|
|
}
|
|
|
|
factory Item.fromMap(Map<String, dynamic> map) {
|
|
return Item(
|
|
id: map['id'],
|
|
name: map['name'],
|
|
categoryId: map['categoryId'],
|
|
locationId: map['locationId'],
|
|
description: map['description'],
|
|
purchaseDate: map['purchaseDate'],
|
|
isInUse: map['isInUse'],
|
|
createdAt: map['createdAt'],
|
|
updatedAt: map['updatedAt'],
|
|
);
|
|
}
|
|
} |