From eb1c0302b54d9286508a958840114ba891189791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=8D=8E=E8=BD=A9?= <646903573@qq.com> Date: Mon, 16 Nov 2020 16:27:46 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E7=83=AD=E6=A6=9C=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=95=B0=E6=8D=AE=202=E3=80=82=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85=E5=9B=BE=E7=89=87=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hot_ranking_page/hot_ranking_page.dart | 12 +- .../detail_img/goods_details_img.dart | 25 +-- .../goods_details_slide_banner_widget.dart | 10 +- .../hot_ranking_goods/hot_ranking_goods.dart | 154 ++++++++++++++---- .../hot_ranking_list/hot_ranking_bloc.dart | 5 + .../hot_ranking_list/hot_ranking_list.dart | 18 +- 6 files changed, 165 insertions(+), 59 deletions(-) diff --git a/lib/pages/hot_ranking_page/hot_ranking_page.dart b/lib/pages/hot_ranking_page/hot_ranking_page.dart index 85b17b2..01c68b5 100644 --- a/lib/pages/hot_ranking_page/hot_ranking_page.dart +++ b/lib/pages/hot_ranking_page/hot_ranking_page.dart @@ -22,7 +22,7 @@ class HotRankingPage extends StatefulWidget { _HotRankingPageState createState() => _HotRankingPageState(); } -class _HotRankingPageState extends State { +class _HotRankingPageState extends State with AutomaticKeepAliveClientMixin{ @override Widget build(BuildContext context) { print('hot_ranking_page build'); @@ -48,6 +48,10 @@ class _HotRankingPageState extends State { ), ); } + + @override + // TODO: implement wantKeepAlive + bool get wantKeepAlive => true; } class _HotRankingPageContainer extends StatefulWidget { @@ -60,7 +64,7 @@ class _HotRankingPageContainer extends StatefulWidget { __HotRankingPageContainerState(); } -class __HotRankingPageContainerState extends State<_HotRankingPageContainer> { +class __HotRankingPageContainerState extends State<_HotRankingPageContainer> with AutomaticKeepAliveClientMixin{ HotRankingPageBloc _bloc; RefreshController _refreshController; String backgroundImage; @@ -136,6 +140,10 @@ class __HotRankingPageContainerState extends State<_HotRankingPageContainer> { } return list; } + + @override + // TODO: implement wantKeepAlive + bool get wantKeepAlive => true; } class _SilverAppBarDelegate extends SliverPersistentHeaderDelegate { diff --git a/lib/widgets/goods_details/detail_img/goods_details_img.dart b/lib/widgets/goods_details/detail_img/goods_details_img.dart index 6fb550c..ed49ced 100644 --- a/lib/widgets/goods_details/detail_img/goods_details_img.dart +++ b/lib/widgets/goods_details/detail_img/goods_details_img.dart @@ -97,18 +97,19 @@ class _GoodsDetailsImgWidgetContainerState return Column( children: model.image_detail_list.map((item) { return GestureDetector( - onTap: () { - if(item!=null){ - PhotoPreview.showPhotoPreviewByimages( - context, [item], - currentIndex: 0); - } - }, - child: CachedNetworkImage( - imageUrl: item ?? '', - fit: BoxFit.fitWidth, - ), - ); + onTap: () { + if (item != null) { + PhotoPreview.showPhotoPreviewByimages(context, [item], + currentIndex: 0, heroTagSuffix: "bottom"); + } + }, + child: Hero( + tag: item + "bottom", + child: CachedNetworkImage( + imageUrl: item ?? '', + fit: BoxFit.fitWidth, + ), + )); }).toList(), ); } else { diff --git a/lib/widgets/goods_details/slide_banner/goods_details_slide_banner_widget.dart b/lib/widgets/goods_details/slide_banner/goods_details_slide_banner_widget.dart index 32df501..1c09104 100644 --- a/lib/widgets/goods_details/slide_banner/goods_details_slide_banner_widget.dart +++ b/lib/widgets/goods_details/slide_banner/goods_details_slide_banner_widget.dart @@ -46,8 +46,9 @@ class _GoodsDetailsSlideBannerContainerState /// 子元素点击事件 void _itemOnClick(String model, List images, int index) { print('点击了 $model'); - if(images!=null){ - PhotoPreview.showPhotoPreviewByimages(context, images, currentIndex: index); + if (images != null) { + PhotoPreview.showPhotoPreviewByimages(context, images, + currentIndex: index, heroTagSuffix: "top"); } } @@ -108,7 +109,10 @@ class _GoodsDetailsSlideBannerContainerState String items = datas.image_list[index]; return Container( width: double.infinity, - child: CachedNetworkImage(imageUrl: items ?? '', fit: BoxFit.cover), + child: Hero( + tag: items + "top", + child: CachedNetworkImage( + imageUrl: items ?? '', fit: BoxFit.cover)), ); }, itemCount: datas?.image_list?.length ?? 0, diff --git a/lib/widgets/hot_ranking/hot_ranking_goods/hot_ranking_goods.dart b/lib/widgets/hot_ranking/hot_ranking_goods/hot_ranking_goods.dart index 0598715..da05d52 100644 --- a/lib/widgets/hot_ranking/hot_ranking_goods/hot_ranking_goods.dart +++ b/lib/widgets/hot_ranking/hot_ranking_goods/hot_ranking_goods.dart @@ -12,25 +12,31 @@ class HotRankingGoods extends StatelessWidget { HotRankingListModel styleModel; int index; - HotRankingGoods({Key key, this.good, this.styleModel, this.index}) : super(key: key); + HotRankingGoods({Key key, this.good, this.styleModel, this.index}) + : super(key: key); @override Widget build(BuildContext context) { var indexImage; - if (styleModel.hotRankIconList != null && styleModel.hotRankIconList.length > 0 && styleModel.hotRankIconList.length - 1 >= index) { + if (styleModel.hotRankIconList != null && + styleModel.hotRankIconList.length > 0 && + styleModel.hotRankIconList.length - 1 >= index) { indexImage = styleModel.hotRankIconList[index]; } Providers providers = getProvider(good.provider); return GestureDetector( onTap: () { - RouterUtil.route(SkipModel(skipIdentifier: "goods_details"), good?.toJson(), context); + RouterUtil.route(SkipModel(skipIdentifier: "goods_details"), + good?.toJson(), context); }, child: Stack( children: [ Container( padding: EdgeInsets.all(15.w), - margin: EdgeInsets.only(top: 8.w, bottom: 8.w, left: 25.w, right: 25.w), - decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(15.w)), + margin: + EdgeInsets.only(top: 8.w, bottom: 8.w, left: 25.w, right: 25.w), + decoration: BoxDecoration( + color: Colors.white, borderRadius: BorderRadius.circular(15.w)), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -40,11 +46,15 @@ class HotRankingGoods extends StatelessWidget { height: 254.w, child: ClipRRect( borderRadius: BorderRadius.circular(6), - child: CachedNetworkImage( - imageUrl: good?.goodImage ?? '', + child: Hero( + tag: (good?.goodImage ?? "") + "top", + child: CachedNetworkImage( + imageUrl: good?.goodImage ?? '', + ), ), ), - decoration: BoxDecoration(borderRadius: BorderRadius.circular(6)), + decoration: + BoxDecoration(borderRadius: BorderRadius.circular(6)), ), /// 商品图片右边视图 @@ -64,8 +74,12 @@ class HotRankingGoods extends StatelessWidget { WidgetSpan( alignment: ui.PlaceholderAlignment.middle, child: Container( - padding: EdgeInsets.only(left: 4.w, right: 4.w, top: 1, bottom: 1), - decoration: BoxDecoration(color: HexColor.fromHex(providers.providerBgColor), borderRadius: BorderRadius.circular(2.5)), + padding: EdgeInsets.only( + left: 4.w, right: 4.w, top: 1, bottom: 1), + decoration: BoxDecoration( + color: HexColor.fromHex( + providers.providerBgColor), + borderRadius: BorderRadius.circular(2.5)), child: Text( good.providerName ?? "", style: TextStyle( @@ -79,7 +93,12 @@ class HotRankingGoods extends StatelessWidget { child: SizedBox( width: 4.h, )), - TextSpan(text: good.goodTitle, style: TextStyle(color: HexColor.fromHex(styleModel.titleColor ?? ""), fontSize: 30.sp)) + TextSpan( + text: good.goodTitle, + style: TextStyle( + color: HexColor.fromHex( + styleModel.titleColor ?? ""), + fontSize: 30.sp)) ])), /// 优惠券 @@ -88,16 +107,32 @@ class HotRankingGoods extends StatelessWidget { good.coupon == "" ? Container() : Container( - margin: EdgeInsets.only(top: 4, bottom: 4, right: 15.w), + margin: EdgeInsets.only( + top: 4, bottom: 4, right: 15.w), decoration: BoxDecoration( - borderRadius: BorderRadius.circular(2.5), - color: HexColor.fromHex(styleModel.couponCommission.left.couponBgColor), - image: DecorationImage(image: CachedNetworkImageProvider(styleModel.couponCommission.left.couponBgImg))), + borderRadius: BorderRadius.circular(2.5), + color: HexColor.fromHex(styleModel + .couponCommission.left.couponBgColor), + image: DecorationImage( + image: CachedNetworkImageProvider( + styleModel.couponCommission.left + .couponBgImg))), child: Padding( - padding: const EdgeInsets.only(left: 8, right: 8, top: 2, bottom: 2), + padding: const EdgeInsets.only( + left: 8, right: 8, top: 2, bottom: 2), child: Text( - (good.coupon ?? "") + (styleModel.couponCommission.left.couonText ?? ""), - style: TextStyle(color: HexColor.fromHex(styleModel.couponCommission.left.couponFontColor), fontSize: 22.sp, fontFamily: 'Din', package: 'zhiying_base_widget'), + (good.coupon ?? "") + + (styleModel.couponCommission.left + .couonText ?? + ""), + style: TextStyle( + color: HexColor.fromHex(styleModel + .couponCommission + .left + .couponFontColor), + fontSize: 22.sp, + fontFamily: 'Din', + package: 'zhiying_base_widget'), ), ), ), @@ -106,14 +141,33 @@ class HotRankingGoods extends StatelessWidget { : Container( margin: EdgeInsets.only(top: 4, bottom: 4), decoration: BoxDecoration( - borderRadius: BorderRadius.circular(2.5), - color: HexColor.fromHex(styleModel.couponCommission.right.commissionBgColor ?? ""), - image: DecorationImage(image: CachedNetworkImageProvider(styleModel.couponCommission.right.commissionBgImg ?? ""))), + borderRadius: BorderRadius.circular(2.5), + color: HexColor.fromHex(styleModel + .couponCommission + .right + .commissionBgColor ?? + ""), + image: DecorationImage( + image: CachedNetworkImageProvider( + styleModel.couponCommission.right + .commissionBgImg ?? + ""))), child: Padding( - padding: const EdgeInsets.only(left: 8, right: 8, top: 2, bottom: 2), + padding: const EdgeInsets.only( + left: 8, right: 8, top: 2, bottom: 2), child: Text( - (styleModel.couponCommission.right.commissionText ?? "") + (good.commission ?? ""), - style: TextStyle(color: HexColor.fromHex(styleModel.couponCommission.right.commissionFontColor), fontSize: 22.sp,fontFamily: 'Din', package: 'zhiying_base_widget'), + (styleModel.couponCommission.right + .commissionText ?? + "") + + (good.commission ?? ""), + style: TextStyle( + color: HexColor.fromHex(styleModel + .couponCommission + .right + .commissionFontColor), + fontSize: 22.sp, + fontFamily: 'Din', + package: 'zhiying_base_widget'), ), ), ), @@ -130,12 +184,21 @@ class HotRankingGoods extends StatelessWidget { padding: EdgeInsets.only(bottom: 6.sp), child: Text( "¥", - style: TextStyle(color: HexColor.fromHex(styleModel.currentPriceColor ?? ""), fontSize: 20.sp), + style: TextStyle( + color: HexColor.fromHex( + styleModel.currentPriceColor ?? ""), + fontSize: 20.sp), ), ), Text( good.currentPrice ?? "", - style: TextStyle(color: HexColor.fromHex(styleModel.currentPriceColor ?? ""), fontSize: 40.sp,fontWeight: FontWeight.bold ,fontFamily: 'Din', package: 'zhiying_base_widget'), + style: TextStyle( + color: HexColor.fromHex( + styleModel.currentPriceColor ?? ""), + fontSize: 40.sp, + fontWeight: FontWeight.bold, + fontFamily: 'Din', + package: 'zhiying_base_widget'), ), SizedBox( width: 6, @@ -144,7 +207,13 @@ class HotRankingGoods extends StatelessWidget { padding: EdgeInsets.only(bottom: 4.sp), child: Text( "¥" + good.marketPrice ?? "", - style: TextStyle(color: HexColor.fromHex(styleModel.marketPriceColor ?? ""), fontSize: 22.sp, decoration: TextDecoration.lineThrough, fontFamily: 'Din', package: 'zhiying_base_widget'), + style: TextStyle( + color: HexColor.fromHex( + styleModel.marketPriceColor ?? ""), + fontSize: 22.sp, + decoration: TextDecoration.lineThrough, + fontFamily: 'Din', + package: 'zhiying_base_widget'), ), ), ], @@ -167,11 +236,17 @@ class HotRankingGoods extends StatelessWidget { padding: EdgeInsets.only( left: 40.w, ), - margin: EdgeInsets.only(right: 20, left: 20.w), - color: HexColor.fromHex(styleModel.hotRank.bgColor ?? ""), + margin: + EdgeInsets.only(right: 20, left: 20.w), + color: HexColor.fromHex( + styleModel.hotRank.bgColor ?? ""), child: Text( "热销" + good.inorderCount + "件", - style: TextStyle(color: Colors.white, fontSize: 22.sp, fontFamily: 'Din', package: 'zhiying_base_widget'), + style: TextStyle( + color: Colors.white, + fontSize: 22.sp, + fontFamily: 'Din', + package: 'zhiying_base_widget'), ), )) ], @@ -180,10 +255,12 @@ class HotRankingGoods extends StatelessWidget { width: 48.w, height: 48.w, child: CachedNetworkImage( - imageUrl: styleModel?.hotRank?.hotSaleImg ?? "", + imageUrl: + styleModel?.hotRank?.hotSaleImg ?? "", width: 48.w, height: 48.w, - placeholder: (context, _) => Container(color: Colors.yellow), + placeholder: (context, _) => + Container(color: Colors.yellow), fit: BoxFit.fill, ), ), @@ -193,8 +270,13 @@ class HotRankingGoods extends StatelessWidget { height: 48.h, width: 127.w, decoration: BoxDecoration( - image: DecorationImage(image: CachedNetworkImageProvider(styleModel.hotRank.buyNowImg ?? ""), fit: BoxFit.fitWidth), - borderRadius: BorderRadius.circular(20)), + image: DecorationImage( + image: CachedNetworkImageProvider( + styleModel.hotRank.buyNowImg ?? + ""), + fit: BoxFit.fitWidth), + borderRadius: + BorderRadius.circular(20)), margin: EdgeInsets.only(right: 0), )) ], @@ -210,7 +292,9 @@ class HotRankingGoods extends StatelessWidget { Align( alignment: Alignment.topLeft, child: Container( - decoration: BoxDecoration(image: DecorationImage(image: CachedNetworkImageProvider(indexImage ?? ""))), + decoration: BoxDecoration( + image: DecorationImage( + image: CachedNetworkImageProvider(indexImage ?? ""))), margin: EdgeInsets.only(left: 40.w, top: 8.h), height: 60.w, width: 60.w, diff --git a/lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_bloc.dart b/lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_bloc.dart index ccfefdc..fbebe46 100644 --- a/lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_bloc.dart +++ b/lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_bloc.dart @@ -1,6 +1,10 @@ import 'dart:async'; import 'dart:convert'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; +import 'package:zhiying_base_widget/dialog/loading/loading_dialog.dart'; import 'package:zhiying_base_widget/widgets/hot_ranking/hot_ranking_list/model/hot_ranking_list_data_model.dart'; import 'package:zhiying_comm/util/base_bloc.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; @@ -35,6 +39,7 @@ class HotRankingListBloc extends BlocBase { NetUtil.request( '/api/v1/rec/taobao?type_id=' + typeId + '&page=' + page.toString(), method: NetMethod.GET, onSuccess: (data) { + complete(); isLoading = false; _loadData(data); diff --git a/lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_list.dart b/lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_list.dart index db0cc27..f686bfc 100644 --- a/lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_list.dart +++ b/lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_list.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; +import 'package:zhiying_base_widget/dialog/loading/loading_dialog.dart'; import 'package:zhiying_base_widget/pages/hot_ranking_page/hot_ranking_page_bloc.dart'; import 'package:zhiying_base_widget/widgets/hot_ranking/hot_ranking_goods/hot_ranking_goods.dart'; import 'package:zhiying_base_widget/widgets/hot_ranking/hot_ranking_list/model/hot_ranking_list_data_model.dart'; @@ -23,7 +24,7 @@ class HotRankingList extends StatefulWidget { } class _HotRankingState extends State - with TickerProviderStateMixin { + with TickerProviderStateMixin, AutomaticKeepAliveClientMixin { HotRankingListBloc _bloc; TabController _tabController; RefreshController _refreshController; @@ -33,6 +34,8 @@ class _HotRankingState extends State ScrollController _scrollcontroller; + bool isFirstTime=true; + @override void initState() { _bloc = HotRankingListBloc(); @@ -45,6 +48,8 @@ class _HotRankingState extends State if (event.containsKey('type') && event['type'] == "loadData") { _bloc.currentPage = 1; _bloc.loadData(event['type_id'], _bloc.currentPage, () {}); + _scrollcontroller.animateTo(0, + duration: Duration(milliseconds: 500), curve: Curves.bounceInOut); } }); } @@ -72,12 +77,7 @@ class _HotRankingState extends State return HotRankingSkeleton(); } else { goods = snapshot.data.good; - if (_bloc.currentPage == 1) { - Future.delayed(Duration(milliseconds: 100), () { - _scrollcontroller.animateTo(0, - duration: Duration(milliseconds: 100), curve: Curves.ease); - }); - } + return SmartRefresher( controller: _refreshController, enablePullDown: true, @@ -121,4 +121,8 @@ class _HotRankingState extends State index: index, ); } + + @override + // TODO: implement wantKeepAlive + bool get wantKeepAlive => true; }