Browse Source

1、今日热榜进入商品详情的预加载

2、商品详情的优化
tags/0.0.1
PH2 4 years ago
parent
commit
130c87ccb9
8 changed files with 128 additions and 113 deletions
  1. +21
    -11
      lib/widgets/goods_details/coupon/counpon_widget.dart
  2. +13
    -2
      lib/widgets/goods_details/detail_img/goods_details_img.dart
  3. +54
    -81
      lib/widgets/goods_details/footer/goods_details_footer_widget.dart
  4. +8
    -2
      lib/widgets/goods_details/slide_banner/goods_details_slide_banner_widget.dart
  5. +13
    -2
      lib/widgets/goods_details/store/store_widget.dart
  6. +1
    -2
      lib/widgets/hot_ranking/hot_ranking_goods/hot_ranking_goods.dart
  7. +17
    -12
      lib/widgets/hot_ranking/hot_ranking_list/model/hot_ranking_list_data_model.dart
  8. +1
    -1
      lib/widgets/mine/mine_header/mine_header_container.dart

+ 21
- 11
lib/widgets/goods_details/coupon/counpon_widget.dart View File

@@ -19,18 +19,28 @@ class CounponWidget extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
// return Container(); // return Container();
return BlocProvider<CounponBloc>( return BlocProvider<CounponBloc>(
create: (_) => CounponBloc(repository: CounponRepository())..add(CounponInitEvent(model: model)),
child: CounponWidgetContainer(),
create: (_) => CounponBloc(repository: CounponRepository()), //..add(CounponInitEvent(model: model)),
child: CounponWidgetContainer(model, key: UniqueKey(),),
); );
} }
} }


class CounponWidgetContainer extends StatefulWidget { class CounponWidgetContainer extends StatefulWidget {
final Map<String, dynamic> model;

const CounponWidgetContainer(this.model, {Key key}) : super(key: key);

@override @override
_CounponWidgetContainerState createState() => _CounponWidgetContainerState(); _CounponWidgetContainerState createState() => _CounponWidgetContainerState();
} }


class _CounponWidgetContainerState extends State<CounponWidgetContainer> { class _CounponWidgetContainerState extends State<CounponWidgetContainer> {
@override
void initState() {
BlocProvider.of<CounponBloc>(context).add(CounponInitEvent(model: widget?.model));
super.initState();
}

/// 点击领取 /// 点击领取
void _onJump(CounponModel model) {} void _onJump(CounponModel model) {}


@@ -69,19 +79,18 @@ class _CounponWidgetContainerState extends State<CounponWidgetContainer> {
width: double.infinity, width: double.infinity,
padding: const EdgeInsets.only(left: 18.5, top: 12, bottom: 14), padding: const EdgeInsets.only(left: 18.5, top: 12, bottom: 14),
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage(
image: CachedNetworkImageProvider(
model?.bg_img ??'',
),
fit: BoxFit.fill
)
),
image: DecorationImage(
image: CachedNetworkImageProvider(
model?.bg_img ?? '',
),
fit: BoxFit.fill)),
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
/// 价格 /// 价格
_getPriceWidget(model), _getPriceWidget(model),
const SizedBox(width: 7.5), const SizedBox(width: 7.5),

/// 有效期 /// 有效期
_getTimeWidget(model) _getTimeWidget(model)
], ],
@@ -102,7 +111,8 @@ class _CounponWidgetContainerState extends State<CounponWidgetContainer> {
Text(model?.price_type ?? '¥ ', style: TextStyle(fontSize: 15, color: HexColor.fromHex(model?.price_type_color ?? '#FFFFFF'))), Text(model?.price_type ?? '¥ ', style: TextStyle(fontSize: 15, color: HexColor.fromHex(model?.price_type_color ?? '#FFFFFF'))),


/// 价格 /// 价格
Text(model?.coupon_price ??'100', style: TextStyle(fontSize: 30, color: HexColor.fromHex(model?.coupon_price_color ?? '#FFFFFF'), fontFamily: 'Din', package: 'zhiying_base_widget')),
Text(model?.coupon_price ?? '100',
style: TextStyle(fontSize: 30, color: HexColor.fromHex(model?.coupon_price_color ?? '#FFFFFF'), fontFamily: 'Din', package: 'zhiying_base_widget')),
], ],
); );
} }
@@ -113,7 +123,7 @@ class _CounponWidgetContainerState extends State<CounponWidgetContainer> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
/// 标题 /// 标题
Text(model?.coupon_title ?? '优惠券', style: TextStyle(fontSize: 17, color: HexColor.fromHex( model?.coupon_title_color ?? '#FFFFFF'))),
Text(model?.coupon_title ?? '优惠券', style: TextStyle(fontSize: 17, color: HexColor.fromHex(model?.coupon_title_color ?? '#FFFFFF'))),


/// 到期时间 /// 到期时间
Text(model?.coupon_endtime ?? '有效期至2020-10-01', style: TextStyle(fontSize: 10, color: HexColor.fromHex(model?.coupon_time_color ?? '#FFFFFF'))) Text(model?.coupon_endtime ?? '有效期至2020-10-01', style: TextStyle(fontSize: 10, color: HexColor.fromHex(model?.coupon_time_color ?? '#FFFFFF')))


+ 13
- 2
lib/widgets/goods_details/detail_img/goods_details_img.dart View File

@@ -19,18 +19,29 @@ class GoodsDetailsImgWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider<GoodsDetailsImgBloc>( return BlocProvider<GoodsDetailsImgBloc>(
create: (_) => GoodsDetailsImgBloc(repository: GoodsDetailsImgRepository())..add(GoodsDetailsImgInitEvent(model: model)),
child: GoodsDetailsImgWidgetContainer(),
create: (_) => GoodsDetailsImgBloc(repository: GoodsDetailsImgRepository()),//..add(GoodsDetailsImgInitEvent(model: model)),
child: GoodsDetailsImgWidgetContainer(model, key: UniqueKey(),),
); );
} }
} }


class GoodsDetailsImgWidgetContainer extends StatefulWidget { class GoodsDetailsImgWidgetContainer extends StatefulWidget {

final Map<String, dynamic> model;
const GoodsDetailsImgWidgetContainer(this.model, {Key key}) : super(key: key);

@override @override
_GoodsDetailsImgWidgetContainerState createState() => _GoodsDetailsImgWidgetContainerState(); _GoodsDetailsImgWidgetContainerState createState() => _GoodsDetailsImgWidgetContainerState();
} }


class _GoodsDetailsImgWidgetContainerState extends State<GoodsDetailsImgWidgetContainer> { class _GoodsDetailsImgWidgetContainerState extends State<GoodsDetailsImgWidgetContainer> {

@override
void initState() {
BlocProvider.of<GoodsDetailsImgBloc>(context).add(GoodsDetailsImgInitEvent(model: widget?.model));
super.initState();
}

@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocConsumer<GoodsDetailsImgBloc, GoodsDetailsImgState>( return BlocConsumer<GoodsDetailsImgBloc, GoodsDetailsImgState>(


+ 54
- 81
lib/widgets/goods_details/footer/goods_details_footer_widget.dart View File

@@ -30,10 +30,12 @@ class GoodsDetailsFooterWidget extends StatelessWidget {
visible: !EmptyUtil.isEmpty(model), visible: !EmptyUtil.isEmpty(model),
replacement: GoodsDetailsFooterSkeleton(), replacement: GoodsDetailsFooterSkeleton(),
child: BlocProvider<GoodsDetailsFooterBloc>( child: BlocProvider<GoodsDetailsFooterBloc>(
create: (_) =>
GoodsDetailsFooterBloc(repository: GoodsDetailsFooterRepository())
..add(GoodsDetailsFooterInitEvent(model: model)),
child: GooddsDetailsFooterContainer(model),
create: (_) => GoodsDetailsFooterBloc(repository: GoodsDetailsFooterRepository()),
//..add(GoodsDetailsFooterInitEvent(model: model)),
child: GooddsDetailsFooterContainer(
model,
key: UniqueKey(),
),
), ),
); );
} }
@@ -45,21 +47,24 @@ class GooddsDetailsFooterContainer extends StatefulWidget {
const GooddsDetailsFooterContainer(this.model, {Key key}) : super(key: key); const GooddsDetailsFooterContainer(this.model, {Key key}) : super(key: key);


@override @override
_GooddsDetailsFooterContainerState createState() =>
_GooddsDetailsFooterContainerState();
_GooddsDetailsFooterContainerState createState() => _GooddsDetailsFooterContainerState();
} }


class _GooddsDetailsFooterContainerState
extends State<GooddsDetailsFooterContainer> {
class _GooddsDetailsFooterContainerState extends State<GooddsDetailsFooterContainer> {
UserInfoModel _user; UserInfoModel _user;


@override
void initState() {
BlocProvider.of<GoodsDetailsFooterBloc>(context).add(GoodsDetailsFooterInitEvent(model: widget?.model));
super.initState();
}

/// 打开首页 /// 打开首页
void _openHome() { void _openHome() {
Navigator.pushAndRemoveUntil( Navigator.pushAndRemoveUntil(
context, context,
CupertinoPageRoute(
builder: (BuildContext context) =>
PageFactory.create('homePage', null)),
CupertinoPageRoute(builder: (BuildContext context) => PageFactory.create('homePage', null)),
(Route<dynamic> route) => false, (Route<dynamic> route) => false,
); );
} }
@@ -95,8 +100,7 @@ class _GooddsDetailsFooterContainerState
return; return;
} }
} }
Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => GoodsSharePage(widget.model)));
Navigator.of(context).push(CupertinoPageRoute(builder: (context) => GoodsSharePage(widget.model)));
} }
} }


@@ -166,8 +170,7 @@ class _GooddsDetailsFooterContainerState
return SafeArea( return SafeArea(
child: Container( child: Container(
width: double.infinity, width: double.infinity,
padding: EdgeInsets.only(
bottom: (height > 10 ? 0 : 8), top: 8, left: 21, right: 12.5),
padding: EdgeInsets.only(bottom: (height > 10 ? 0 : 8), top: 8, left: 21, right: 12.5),
decoration: BoxDecoration( decoration: BoxDecoration(
// boxShadow: [ // boxShadow: [
// BoxShadow(color: Colors.grey[300], offset: Offset(0.0, 0.0), blurRadius: 5.0, spreadRadius: 2.0), // BoxShadow(color: Colors.grey[300], offset: Offset(0.0, 0.0), blurRadius: 5.0, spreadRadius: 2.0),
@@ -206,18 +209,12 @@ class _GooddsDetailsFooterContainerState
onTap: () => _openHome(), onTap: () => _openHome(),
child: Padding( child: Padding(
padding: const EdgeInsets.only(right: 35), padding: const EdgeInsets.only(right: 35),
child: _getCustomWidget(model?.home ?? '首页',
model?.home_color ?? '999999', model?.home_icon ?? ''),
child: _getCustomWidget(model?.home ?? '首页', model?.home_color ?? '999999', model?.home_icon ?? ''),
)), )),
GestureDetector( GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () => _collectOnClick(), onTap: () => _collectOnClick(),
child: Padding(
padding: const EdgeInsets.only(right: 0),
child: _getCustomWidget(
model?.collect ?? '收藏',
model?.collect_color ?? '999999',
model?.collect_icon ?? '')))
child: Padding(padding: const EdgeInsets.only(right: 0), child: _getCustomWidget(model?.collect ?? '收藏', model?.collect_color ?? '999999', model?.collect_icon ?? '')))
], ],
); );
} }
@@ -244,40 +241,30 @@ class _GooddsDetailsFooterContainerState
width: 110, width: 110,
// padding: const EdgeInsets.only(left: 30, right: 30, top: 5, bottom: 5), // padding: const EdgeInsets.only(left: 30, right: 30, top: 5, bottom: 5),
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient(colors: [
HexColor.fromHex(model?.share_earn_bg1_color ?? '#FFCA66'),
HexColor.fromHex(model?.share_earn_bg2_color ?? '#FFD961')
], begin: Alignment.centerLeft, end: Alignment.centerRight),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(25), topLeft: Radius.circular(25))),
gradient: LinearGradient(
colors: [HexColor.fromHex(model?.share_earn_bg1_color ?? '#FFCA66'), HexColor.fromHex(model?.share_earn_bg2_color ?? '#FFD961')],
begin: Alignment.centerLeft,
end: Alignment.centerRight),
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(25), topLeft: Radius.circular(25))),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
RichText( RichText(
text: TextSpan(
text: '¥ ',
style: TextStyle(
fontSize: 12,
color: HexColor.fromHex(
model?.share_earn_val_color ?? 'FFFFFF')),
children: [
TextSpan(
text: model?.share_value ?? '0.0',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: HexColor.fromHex(
model?.share_earn_color ?? '#FFFFFF'),
fontFamily: 'Din',
package: 'zhiying_base_widget')),
]),
text: TextSpan(text: '¥ ', style: TextStyle(fontSize: 12, color: HexColor.fromHex(model?.share_earn_val_color ?? 'FFFFFF')), children: [
TextSpan(
text: model?.share_value ?? '0.0',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: HexColor.fromHex(model?.share_earn_color ?? '#FFFFFF'),
fontFamily: 'Din',
package: 'zhiying_base_widget')),
]),
), ),
Text( Text(
model?.share_earn ?? '分享赚', model?.share_earn ?? '分享赚',
style: TextStyle(
color: HexColor.fromHex(model?.share_earn_color ?? '#FFFFFF'),
fontSize: 12),
style: TextStyle(color: HexColor.fromHex(model?.share_earn_color ?? '#FFFFFF'), fontSize: 12),
), ),
], ],
), ),
@@ -296,42 +283,29 @@ class _GooddsDetailsFooterContainerState
height: 44, height: 44,
width: 110, width: 110,
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient(colors: [
HexColor.fromHex(model?.save_earn_bg1_color ?? '#FF6969'),
HexColor.fromHex(model?.save_earn_bg2_color ?? '#FF4646')
], begin: Alignment.centerLeft, end: Alignment.centerRight),
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(25),
topRight: Radius.circular(25))),
gradient: LinearGradient(
colors: [HexColor.fromHex(model?.save_earn_bg1_color ?? '#FF6969'), HexColor.fromHex(model?.save_earn_bg2_color ?? '#FF4646')],
begin: Alignment.centerLeft,
end: Alignment.centerRight),
borderRadius: BorderRadius.only(bottomRight: Radius.circular(25), topRight: Radius.circular(25))),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
RichText( RichText(
text: TextSpan(
text: '¥ ',
style: TextStyle(
fontSize: 12,
color: HexColor.fromHex(
model?.save_earn_val_color ?? 'FFFFFF')),
children: [
TextSpan(
text: model?.slef_buy_value ?? '0.0',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: HexColor.fromHex(
model?.save_earn_val_color ?? '#FFFFFF'),
fontFamily: 'Din',
package: 'zhiying_base_widget',
)),
]),
text: TextSpan(text: '¥ ', style: TextStyle(fontSize: 12, color: HexColor.fromHex(model?.save_earn_val_color ?? 'FFFFFF')), children: [
TextSpan(
text: model?.slef_buy_value ?? '0.0',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: HexColor.fromHex(model?.save_earn_val_color ?? '#FFFFFF'),
fontFamily: 'Din',
package: 'zhiying_base_widget',
)),
]),
), ),
Text(model?.save_earn ?? '自购省',
style: TextStyle(
color:
HexColor.fromHex(model?.save_earn_color ?? '#FFFFFF'),
fontSize: 12))
Text(model?.save_earn ?? '自购省', style: TextStyle(color: HexColor.fromHex(model?.save_earn_color ?? '#FFFFFF'), fontSize: 12))
], ],
), ),
), ),
@@ -354,8 +328,7 @@ class _GooddsDetailsFooterContainerState
const SizedBox(height: 5), const SizedBox(height: 5),


/// 图片 /// 图片
Text(text,
style: TextStyle(color: HexColor.fromHex(textColor), fontSize: 11))
Text(text, style: TextStyle(color: HexColor.fromHex(textColor), fontSize: 11))
], ],
); );
} }


+ 8
- 2
lib/widgets/goods_details/slide_banner/goods_details_slide_banner_widget.dart View File

@@ -19,8 +19,8 @@ class GoodsDetailsSlideBannerWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider<GoodsDetailsSlideBannerBloc>( return BlocProvider<GoodsDetailsSlideBannerBloc>(
create: (_) => GoodsDetailsSlideBannerBloc(repository: GoodsDetailsSlideBannerRepository())..add(GoodsDetailsSlideBannerInitEvent(model: model)),
child: GoodsDetailsSlideBannerContainer(model),
create: (_) => GoodsDetailsSlideBannerBloc(repository: GoodsDetailsSlideBannerRepository()),//..add(GoodsDetailsSlideBannerInitEvent(model: model)),
child: GoodsDetailsSlideBannerContainer(model, key: UniqueKey(),),
); );
} }
} }
@@ -40,6 +40,12 @@ class _GoodsDetailsSlideBannerContainerState extends State<GoodsDetailsSlideBann
print('点击了 $model'); print('点击了 $model');
} }


@override
void initState() {
BlocProvider.of<GoodsDetailsSlideBannerBloc>(context).add(GoodsDetailsSlideBannerInitEvent(model: widget?.model));
super.initState();
}

@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocConsumer<GoodsDetailsSlideBannerBloc, GoodsDetailsSlideBannerState>( return BlocConsumer<GoodsDetailsSlideBannerBloc, GoodsDetailsSlideBannerState>(


+ 13
- 2
lib/widgets/goods_details/store/store_widget.dart View File

@@ -20,18 +20,29 @@ class StoreWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider<StoreBloc>( return BlocProvider<StoreBloc>(
create: (_) => StoreBloc(repository: StoreRepository())..add(StoreInitEvent(model: model)),
child: StoreContainer(),
create: (_) => StoreBloc(repository: StoreRepository()),//..add(StoreInitEvent(model: model)),
child: StoreContainer(model, key: UniqueKey(),),
); );
} }
} }


class StoreContainer extends StatefulWidget { class StoreContainer extends StatefulWidget {
final Map<String, dynamic> model;

const StoreContainer(this.model, {Key key}) : super(key: key);

@override @override
_StoreContainerState createState() => _StoreContainerState(); _StoreContainerState createState() => _StoreContainerState();
} }


class _StoreContainerState extends State<StoreContainer> { class _StoreContainerState extends State<StoreContainer> {

@override
void initState() {
BlocProvider.of<StoreBloc>(context).add(StoreInitEvent(model: widget?.model));
super.initState();
}

/// 点击更多 /// 点击更多
void _onMoreClick() {} void _onMoreClick() {}




+ 1
- 2
lib/widgets/hot_ranking/hot_ranking_goods/hot_ranking_goods.dart View File

@@ -26,8 +26,7 @@ class HotRankingGoods extends StatelessWidget {
Providers providers = getProvider(good.provider); Providers providers = getProvider(good.provider);
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
RouterUtil.route(SkipModel(skipIdentifier: "goods_details"),
{"provider": good.provider, "good_id": good.goodId}, context);
RouterUtil.route(SkipModel(skipIdentifier: "goods_details"), good?.toJson(), context);
}, },
child: Stack( child: Stack(
children: <Widget>[ children: <Widget>[


+ 17
- 12
lib/widgets/hot_ranking/hot_ranking_list/model/hot_ranking_list_data_model.dart View File

@@ -36,19 +36,22 @@ class Good {
String marketPrice; String marketPrice;
String currentPrice; String currentPrice;
String inorderCount; String inorderCount;
Map<String, dynamic> detailData;


Good(
{this.provider,
this.providerName,
this.goodId,
this.goodImage,
this.goodTitle,
this.shopName,
this.coupon,
this.commission,
this.marketPrice,
this.currentPrice,
this.inorderCount});
Good({
this.provider,
this.providerName,
this.goodId,
this.goodImage,
this.goodTitle,
this.shopName,
this.coupon,
this.commission,
this.marketPrice,
this.currentPrice,
this.inorderCount,
this.detailData,
});


Good.fromJson(Map<String, dynamic> json) { Good.fromJson(Map<String, dynamic> json) {
provider = json['provider']; provider = json['provider'];
@@ -62,6 +65,7 @@ class Good {
marketPrice = json['market_price']; marketPrice = json['market_price'];
currentPrice = json['current_price']; currentPrice = json['current_price'];
inorderCount = json['inorder_count']; inorderCount = json['inorder_count'];
detailData = json['detail_data'];
} }


Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@@ -77,6 +81,7 @@ class Good {
data['market_price'] = this.marketPrice; data['market_price'] = this.marketPrice;
data['current_price'] = this.currentPrice; data['current_price'] = this.currentPrice;
data['inorder_count'] = this.inorderCount; data['inorder_count'] = this.inorderCount;
data['detail_data'] = this.detailData;
return data; return data;
} }
} }

+ 1
- 1
lib/widgets/mine/mine_header/mine_header_container.dart View File

@@ -58,7 +58,7 @@ class _MineHeaderContainerState extends State<MineHeaderContainer> {
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(28), borderRadius: BorderRadius.circular(28),
child: CachedNetworkImage( child: CachedNetworkImage(
imageUrl: profile.avatar,
imageUrl: profile?.avatar ?? '',
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
), ),


Loading…
Cancel
Save