- 新增 AddCategoryScreen 页面用于添加分类 - 更新 CategoryScreen 页面,添加浮动按钮用于导航到添加分类页面 - 修改 CategoryDropdown 组件,支持 ItemCategory 模型 - 更新 Item模型,将 location 改为字符串类型 - 修改 ItemScreen 页面,支持新的分类选择逻辑 - 更新数据库表结构,将 location 字段改为 TEXT 类型
72 lines
1.6 KiB
Dart
72 lines
1.6 KiB
Dart
import 'package:item_tracker/screens/item_screens/item_screen.dart';
|
|
|
|
class Item {
|
|
int? id;
|
|
// 名称
|
|
final String name;
|
|
// 分类
|
|
final int? categoryId;
|
|
// 位置
|
|
final String? location;
|
|
// 描述
|
|
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.location,
|
|
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': location,
|
|
'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'],
|
|
location: map['location'],
|
|
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'],
|
|
);
|
|
}
|
|
} |