diff --git a/lib/models/market/goods_detail_model.dart b/lib/models/market/goods_detail_model.dart index 99a52280..7c24a3b9 100644 --- a/lib/models/market/goods_detail_model.dart +++ b/lib/models/market/goods_detail_model.dart @@ -43,6 +43,25 @@ class GoodsDetailModel extends Equatable { @override List get props => throw UnimplementedError(); + factory GoodsDetailModel.fail() => GoodsDetailModel( + 0, + '', + '', + 0.0, + 0.0, + '', + 0, + '', + '', + [], + 0, + '', + '', + '', + [], + 0, + ); + factory GoodsDetailModel.fromJson(Map json) => _$GoodsDetailModelFromJson(json); } diff --git a/lib/ui/market/goods/goods_detail_page.dart b/lib/ui/market/goods/goods_detail_page.dart index a5b38b4a..f8b56fd2 100644 --- a/lib/ui/market/goods/goods_detail_page.dart +++ b/lib/ui/market/goods/goods_detail_page.dart @@ -72,14 +72,14 @@ class _GoodsDetailPageState extends State { firstRefresh: true, header: MaterialHeader(), onRefresh: () async { - BaseModel baseModel = await NetUtil().get(API.market.goodsDetail, - params: { - "goodsId": widget.id, - "id": userProvider.userDetailModel!.id - }); - if (baseModel.status ?? false) { + BaseModel baseModel = await NetUtil().get( + API.market.goodsDetail, + params: {"goodsId": widget.id}, + ); + if (baseModel.status == true && baseModel.data != null) { _goodsModel = GoodsDetailModel.fromJson(baseModel.data); } else { + _goodsModel = GoodsDetailModel.fail(); BotToast.showText(text: baseModel.message ?? '未知错误'); } baseModel = await NetUtil().get(API.market.hotTop); diff --git a/lib/utils/network/base_model.dart b/lib/utils/network/base_model.dart index 1b22c35d..319ce908 100644 --- a/lib/utils/network/base_model.dart +++ b/lib/utils/network/base_model.dart @@ -2,7 +2,7 @@ class BaseModel { int? code; String? message; bool? status; - dynamic data; + dynamic? data; BaseModel({ this.code, this.message,