- 移除 ItemScopedModel,改用 ItemProvider - 更新 addItem 屏幕,使用 ItemProvider 添加物品 - 修改物品列表屏幕,使用 ItemProvider 加载和刷新数据 - 更新 main 函数,添加 ItemProvider
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 String isInUse;
|
|
final DateTime? createdAt;
|
|
final DateTime? updatedAt;
|
|
|
|
Item({
|
|
this.id,
|
|
required this.name,
|
|
this.categoryId,
|
|
this.locationId,
|
|
this.description,
|
|
this.purchaseDate,
|
|
this.isInUse = 'no',
|
|
this.createdAt,
|
|
this.updatedAt,
|
|
});
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'id': id,
|
|
'name': name,
|
|
'category_id': categoryId,
|
|
'location_id': locationId,
|
|
'description': description,
|
|
'purchase_date': purchaseDate,
|
|
'is_in_use': isInUse,
|
|
'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'],
|
|
purchaseDate: map['purchase_date'],
|
|
isInUse: map['is_in_use'],
|
|
createdAt: map['created_at'],
|
|
updatedAt: map['updated_at'],
|
|
);
|
|
}
|
|
} |