From dc6288e67447359c8ba7d024964d4463c5170394 Mon Sep 17 00:00:00 2001 From: PH2 <1293456824@qq.com> Date: Mon, 19 Apr 2021 14:21:25 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=A0=E4=BD=8D=E5=9B=BE=202=E3=80=81?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E7=BB=93=E6=9E=9C=E9=A1=B5=E4=B8=A4=E5=88=97?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8D=E8=83=BD=E5=8A=A0=E8=BD=BD=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A=E7=9A=84bug=203=E3=80=81=E6=90=9C=E7=B4=A2=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E8=AF=B7=E6=B1=82=E5=8F=82=E6=95=B0=E5=8E=BB=E6=8E=89?= =?UTF-8?q?size=EF=BC=8C=E6=A0=B9=E6=8D=AE=E8=BF=94=E5=9B=9E=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=95=BF=E5=BA=A6=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home/home_goods/home_goods_item.dart | 27 ++++++++++++++----- .../home_goods/home_goods_item_single.dart | 19 +++++++++++++ .../bloc/search_result_goods_list_bloc.dart | 8 +++--- .../search_result_goods_list_repository.dart | 4 +-- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/lib/widgets/home/home_goods/home_goods_item.dart b/lib/widgets/home/home_goods/home_goods_item.dart index a44fa00..2fdb6fa 100644 --- a/lib/widgets/home/home_goods/home_goods_item.dart +++ b/lib/widgets/home/home_goods/home_goods_item.dart @@ -46,13 +46,14 @@ class HomeGoodsItem extends StatelessWidget { Container( width: double.infinity, margin: EdgeInsets.only(right: 0), - child: ClipRRect( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(7.5), - topRight: Radius.circular(7.5)), - child: CachedNetworkImage( - imageUrl: goods?.goodImage ?? '', - fit: BoxFit.fitWidth, + child: ClipRRect(borderRadius: BorderRadius.only(topLeft: Radius.circular(7.5), topRight: Radius.circular(7.5)), + child: CachedNetworkImage(imageUrl: goods?.goodImage ?? '', fit: BoxFit.fitWidth, + placeholder: (context, url) { + return _createShimmerWidget(width: double.infinity); + }, + errorWidget: (context, url, error,) { + return _createShimmerWidget(width: double.infinity); + }, ), ), ), @@ -352,4 +353,16 @@ class HomeGoodsItem extends StatelessWidget { style: TextStyle(fontSize: 11, color: HexColor.fromHex('#999999')), ); } + + /// 商品占位骨架视图 + Widget _createShimmerWidget({double width, double height}) { + //修改后返回默认图片 + return Image.asset( + 'assets/images/occupation_map/occupation_map.png', + package: 'zhiying_base_widget', + width: width, + height: height, + fit: BoxFit.fill, + ); + } } diff --git a/lib/widgets/home/home_goods/home_goods_item_single.dart b/lib/widgets/home/home_goods/home_goods_item_single.dart index 8dc6b31..7670128 100644 --- a/lib/widgets/home/home_goods/home_goods_item_single.dart +++ b/lib/widgets/home/home_goods/home_goods_item_single.dart @@ -59,6 +59,12 @@ class HomeGoodsItemSingle extends StatelessWidget { child: CachedNetworkImage( imageUrl: goods.goodImage, fit: BoxFit.fitHeight, + placeholder: (context, url) { + return _createShimmerWidget(width: double.infinity, height: double.infinity); + }, + errorWidget: (BuildContext context, String url, dynamic error) { + return _createShimmerWidget(width: double.infinity, height: double.infinity); + }, ), ), ), @@ -427,4 +433,17 @@ class HomeGoodsItemSingle extends StatelessWidget { ], ); } + + /// 商品占位骨架视图 + Widget _createShimmerWidget({double width, double height}) { + //修改后返回默认图片 + return Image.asset( + 'assets/images/occupation_map/occupation_map.png', + package: 'zhiying_base_widget', + width: width, + height: height, + fit: BoxFit.fill, + ); + } + } diff --git a/lib/widgets/search_result/goods_list/bloc/search_result_goods_list_bloc.dart b/lib/widgets/search_result/goods_list/bloc/search_result_goods_list_bloc.dart index 9430d19..c9c2d50 100644 --- a/lib/widgets/search_result/goods_list/bloc/search_result_goods_list_bloc.dart +++ b/lib/widgets/search_result/goods_list/bloc/search_result_goods_list_bloc.dart @@ -35,8 +35,8 @@ class SearchResultGoodsListBloc extends Bloc _mapOnLoadToState(SearchResultGoodsListOnLoadEvent event, SearchResultGoodsListLoadedState state) async* { + Stream _mapOnLoadToState(SearchResultGoodsListOnLoadEvent event) async* { var result = await repository.fetchLoadData(); if (!EmptyUtil.isEmpty(result)) { yield SearchResultGoodsListLoadSuccessState(); @@ -93,7 +93,7 @@ class SearchResultGoodsListBloc extends Bloc= MAX) { + if ((data?.length ?? 0) > 0) { _hasNomore = true; ++_currentPage; } else {