- 将 AddItemScreen 中的各个字段提取为独立的 Widget - 新增 CategoryDropdown、DatePickerField、DescriptionField 等组件 - 优化 Item 模型,使用 ItemIsUse 枚举替代字符串表示是否使用 - 在数据库中添加 price 字段- 重构表单提交逻辑,使用新的组件进行数据采集
72 lines
1.7 KiB
Dart
72 lines
1.7 KiB
Dart
import 'package:item_tracker/screens/item_screens/add_item_screen.dart';
|
|
|
|
class Item {
|
|
int? id;
|
|
// 名称
|
|
final String name;
|
|
// 分类
|
|
final int? categoryId;
|
|
// 位置
|
|
final int? locationId;
|
|
// 描述
|
|
final String? description;
|
|
// 价格
|
|
final double? price;
|
|
// 购买日期
|
|
final DateTime? purchaseDate;
|
|
// 是否使用
|
|
final ItemIsUse? isInUse;
|
|
// 数据状态 -normal -deleted
|
|
final String? status;
|
|
// 创建时间
|
|
final DateTime? createdAt;
|
|
// 更新时间
|
|
final DateTime? updatedAt;
|
|
|
|
Item({
|
|
this.id,
|
|
required this.name,
|
|
this.categoryId,
|
|
this.locationId,
|
|
this.description,
|
|
this.price,
|
|
this.purchaseDate,
|
|
this.isInUse = ItemIsUse.no,
|
|
this.status = 'normal',
|
|
this.createdAt,
|
|
this.updatedAt,
|
|
});
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'name': name,
|
|
'category_id': categoryId,
|
|
'location_id': locationId,
|
|
'description': description,
|
|
'price': price,
|
|
'purchase_date': purchaseDate,
|
|
'is_in_use': isInUse?.toInt(),
|
|
'status': status,
|
|
'created_at': createdAt,
|
|
'updated_at': updatedAt,
|
|
};
|
|
}
|
|
|
|
factory Item.fromMap(Map<String, dynamic> map) {
|
|
return Item(
|
|
id: map['id'],
|
|
name: map['name'],
|
|
categoryId: map['category_id'],
|
|
locationId: map['location_id'],
|
|
description: map['description'],
|
|
price: map['price'],
|
|
purchaseDate: map['purchase_date'],
|
|
isInUse: map['is_in_use'] != null
|
|
? ItemIsUseX.fromInt(int.parse(map['is_in_use'].toString()))
|
|
: ItemIsUse.no,
|
|
status: map['status'],
|
|
createdAt: map['created_at'],
|
|
updatedAt: map['updated_at'],
|
|
);
|
|
}
|
|
} |