Parcourir la source

1.优化热榜加载数据

2。优化商品详情图片预览动画
tags/0.0.2+7^2
杨华轩 il y a 4 ans
Parent
révision
eb1c0302b5
6 fichiers modifiés avec 165 ajouts et 59 suppressions
  1. +10
    -2
      lib/pages/hot_ranking_page/hot_ranking_page.dart
  2. +13
    -12
      lib/widgets/goods_details/detail_img/goods_details_img.dart
  3. +7
    -3
      lib/widgets/goods_details/slide_banner/goods_details_slide_banner_widget.dart
  4. +119
    -35
      lib/widgets/hot_ranking/hot_ranking_goods/hot_ranking_goods.dart
  5. +5
    -0
      lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_bloc.dart
  6. +11
    -7
      lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_list.dart

+ 10
- 2
lib/pages/hot_ranking_page/hot_ranking_page.dart Voir le fichier

@@ -22,7 +22,7 @@ class HotRankingPage extends StatefulWidget {
_HotRankingPageState createState() => _HotRankingPageState();
}

class _HotRankingPageState extends State<HotRankingPage> {
class _HotRankingPageState extends State<HotRankingPage> with AutomaticKeepAliveClientMixin{
@override
Widget build(BuildContext context) {
print('hot_ranking_page build');
@@ -48,6 +48,10 @@ class _HotRankingPageState extends State<HotRankingPage> {
),
);
}

@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 {


+ 13
- 12
lib/widgets/goods_details/detail_img/goods_details_img.dart Voir le fichier

@@ -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 {


+ 7
- 3
lib/widgets/goods_details/slide_banner/goods_details_slide_banner_widget.dart Voir le fichier

@@ -46,8 +46,9 @@ class _GoodsDetailsSlideBannerContainerState
/// 子元素点击事件
void _itemOnClick(String model, List<String> 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,


+ 119
- 35
lib/widgets/hot_ranking/hot_ranking_goods/hot_ranking_goods.dart Voir le fichier

@@ -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: <Widget>[
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: <Widget>[
@@ -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,


+ 5
- 0
lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_bloc.dart Voir le fichier

@@ -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);


+ 11
- 7
lib/widgets/hot_ranking/hot_ranking_list/hot_ranking_list.dart Voir le fichier

@@ -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<HotRankingList>
with TickerProviderStateMixin {
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
HotRankingListBloc _bloc;
TabController _tabController;
RefreshController _refreshController;
@@ -33,6 +34,8 @@ class _HotRankingState extends State<HotRankingList>

ScrollController _scrollcontroller;

bool isFirstTime=true;

@override
void initState() {
_bloc = HotRankingListBloc();
@@ -45,6 +48,8 @@ class _HotRankingState extends State<HotRankingList>
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<HotRankingList>
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<HotRankingList>
index: index,
);
}

@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
}

Chargement…
Annuler
Enregistrer