Files
jiu/client/lib/models/product.dart
T
wangjia d717fb3735 feat(client): 全模块 API 对接 + 修复登陆跳转 + 菜单 UI 优化
API 对接:
- 入库/出库/库存/财务/往来单位/基础数据全部对接后端 REST API
- 新增 repositories、providers、models 层,统一分层架构
- auth 从 flutter_secure_storage 迁移到 shared_preferences

登陆跳转修复:
- 将 _RouterNotifier 提取为独立 Riverpod provider,appRouterProvider
  使用 ref.read 避免依赖链导致 router 重建后跳回 /login
- redirect 函数新增 initialized 守卫,防止 auth 未恢复时误重定向
- 添加调试日志(Router/Auth/ApiClient)定位 401 触发的 logout 链路

退出菜单 UI:
- 去掉 ListTile,改用 Row + 自定义 padding,文字左对齐
- MouseRegion + AnimatedContainer 实现 hover 高亮(普通项蓝底/退出红底)
- 菜单圆角 6px,elevation 8,分割线高度 1px

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 22:20:28 +08:00

74 lines
2.2 KiB
Dart

class Product {
final int id;
final String code;
final String? barcode;
final String name;
final String? series;
final String? spec;
final String unit;
final int? categoryId;
final String? brand;
final double? purchasePrice;
final double? salePrice;
final int? minStock;
final String? remark;
final Map<String, dynamic>? customFields;
const Product({
required this.id,
required this.code,
this.barcode,
required this.name,
this.series,
this.spec,
required this.unit,
this.categoryId,
this.brand,
this.purchasePrice,
this.salePrice,
this.minStock,
this.remark,
this.customFields,
});
factory Product.fromJson(Map<String, dynamic> json) => Product(
id: (json['id'] as num).toInt(),
code: json['code'] as String? ?? '',
barcode: json['barcode'] as String?,
name: json['name'] as String,
series: json['series'] as String?,
spec: json['spec'] as String?,
unit: json['unit'] as String? ?? '',
categoryId: json['category_id'] != null
? (json['category_id'] as num).toInt()
: null,
brand: json['brand'] as String?,
purchasePrice: json['purchase_price'] != null
? (json['purchase_price'] as num).toDouble()
: null,
salePrice: json['sale_price'] != null
? (json['sale_price'] as num).toDouble()
: null,
minStock: json['min_stock'] != null
? (json['min_stock'] as num).toInt()
: null,
remark: json['remark'] as String?,
customFields: json['custom_fields'] as Map<String, dynamic>?,
);
Map<String, dynamic> toJson() => {
'code': code,
if (barcode != null) 'barcode': barcode,
'name': name,
if (series != null) 'series': series,
if (spec != null) 'spec': spec,
'unit': unit,
if (categoryId != null) 'category_id': categoryId,
if (brand != null) 'brand': brand,
if (purchasePrice != null) 'purchase_price': purchasePrice,
if (salePrice != null) 'sale_price': salePrice,
if (minStock != null) 'min_stock': minStock,
if (remark != null) 'remark': remark,
};
}