Browse Source

1、商品详情跳转过渡动画

tags/0.0.2+8
PH2 4 years ago
parent
commit
b00cbc5989
6 changed files with 59 additions and 29 deletions
  1. +2
    -0
      lib/pages/goods_details_page/bloc/goods_details_page_bloc.dart
  2. +37
    -12
      lib/pages/goods_details_page/bloc/goods_details_page_repository.dart
  3. +1
    -1
      lib/widgets/goods_details/coupon/counpon_widget.dart
  4. +12
    -8
      lib/widgets/goods_details/coupon/model/counpon_model.dart
  5. +3
    -7
      lib/widgets/goods_details/footer/goods_details_footer_widget.dart
  6. +4
    -1
      lib/widgets/goods_details/footer/model/goods_details_footer_model.dart

+ 2
- 0
lib/pages/goods_details_page/bloc/goods_details_page_bloc.dart View File

@@ -43,5 +43,7 @@ class GoodsDetailsPageBloc extends Bloc<GoodsDetailsPageEvent, GoodsDetailsPageS
} else { } else {
yield GoodsDetailsPageErrorState(); yield GoodsDetailsPageErrorState();
} }
/// 缓存详情跳转过渡样式,可以加快UI渲染。
await repository.cacheTurnChainStyleData();
} }
} }

+ 37
- 12
lib/pages/goods_details_page/bloc/goods_details_page_repository.dart View File

@@ -1,10 +1,31 @@
import 'dart:convert'; import 'dart:convert';
import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:zhiying_comm/util/turn_chain/turn_chain_util.dart';


class GoodsDetailsPageRepository { class GoodsDetailsPageRepository {
// 商品详情的封面图片
String _parentGoodsCoverImg; String _parentGoodsCoverImg;


// 优惠券
String _couponPrice;

// 佣金
String _commission;

// 商品类型
String _providerName;

// 商品ID
String _goodsId;

/// 缓存详情跳转app样式
Future<void> cacheTurnChainStyleData() async {
if (!EmptyUtil.isEmpty(_providerName)) {
bool result = await TurnChainUtil.cacheTurnChainDialogStyle(_goodsId, _providerName, _commission, _couponPrice);
Logger.debug('cache result = $result');
}
}

/// 获取上个页面传进来的数据 /// 获取上个页面传进来的数据
Future<List<Map<String, dynamic>>> fetchParentPageData(final Map<String, dynamic> model) async { Future<List<Map<String, dynamic>>> fetchParentPageData(final Map<String, dynamic> model) async {
try { try {
@@ -13,8 +34,8 @@ class GoodsDetailsPageRepository {
String goodId = model['good_id']?.toString(); String goodId = model['good_id']?.toString();
if (!EmptyUtil.isEmpty(provider) && !EmptyUtil.isEmpty(goodId)) { if (!EmptyUtil.isEmpty(provider) && !EmptyUtil.isEmpty(goodId)) {
Map<String, dynamic> detailData = model['detail_data']; Map<String, dynamic> detailData = model['detail_data'];
String good_image = model['good_image'];
return _baseDataProcess(true, goodId, provider, detailData, good_image);
String goodImage = model['good_image'];
return _baseDataProcess(true, goodId, provider, detailData, goodImage);
} }
} }
} catch (e, s) { } catch (e, s) {
@@ -42,25 +63,30 @@ class GoodsDetailsPageRepository {
} }


/// 数据处理 /// 数据处理
List<Map<String, dynamic>> _baseDataProcess(bool parentInput,String goodId, String provider, final Map<String, dynamic> model, String coverImage) {
List<Map<String, dynamic>> _baseDataProcess(bool parentInput, String goodId, String provider, final Map<String, dynamic> model, String coverImage) {
if (!EmptyUtil.isEmpty(provider) && !EmptyUtil.isEmpty(goodId) && !EmptyUtil.isEmpty(model)) { if (!EmptyUtil.isEmpty(provider) && !EmptyUtil.isEmpty(goodId) && !EmptyUtil.isEmpty(model)) {
try { try {
_couponPrice = model['coupon_price'];
_commission = model['commission'];
_providerName = model['provider_name'];
_goodsId = model['good_id'];
List<Map<String, dynamic>> _pageData = []; List<Map<String, dynamic>> _pageData = [];
Map<String, dynamic> baseData = {'provider': provider, 'good_id': goodId};
Map<String, dynamic> baseData = {'provider': provider, 'good_id': _goodsId, 'commission': _commission, 'coupon_price': _couponPrice};
List<dynamic> modLists = model['mod_list']; List<dynamic> modLists = model['mod_list'];

for (int i = 0; i < modLists.length; i++) { for (int i = 0; i < modLists.length; i++) {
Map<String, dynamic> item = modLists[i]; Map<String, dynamic> item = modLists[i];
// ⚠️ 这里之所以要判断是否是String类型,是因为修改的是父亲页面传进来的model -> data 类型了。把dynamic变成了String // ⚠️ 这里之所以要判断是否是String类型,是因为修改的是父亲页面传进来的model -> data 类型了。把dynamic变成了String
Map<String, dynamic> data = !EmptyUtil.isEmpty(item['data']) ? item['data'] is String ? jsonDecode(item['data']) : item['data'] : new Map<String, dynamic>(); Map<String, dynamic> data = !EmptyUtil.isEmpty(item['data']) ? item['data'] is String ? jsonDecode(item['data']) : item['data'] : new Map<String, dynamic>();


// ⚠️ 为了商品详情的轮播图能够快速加载,故把上一个页面传进来的第一张图片插入到轮播图集合的第一个图片中 // ⚠️ 为了商品详情的轮播图能够快速加载,故把上一个页面传进来的第一张图片插入到轮播图集合的第一个图片中
if(item['mod_name'] == 'product_detail_carousel') {
if (item['mod_name'] == 'product_detail_carousel') {
if (parentInput) { if (parentInput) {
try { try {
var imageList = data['image_list']; var imageList = data['image_list'];
if (!EmptyUtil.isEmpty(imageList)) { if (!EmptyUtil.isEmpty(imageList)) {
_parentGoodsCoverImg = imageList[0]; _parentGoodsCoverImg = imageList[0];
}else if (!EmptyUtil.isEmpty(coverImage)){
} else if (!EmptyUtil.isEmpty(coverImage)) {
_parentGoodsCoverImg = coverImage; _parentGoodsCoverImg = coverImage;
data['image_list'] = [coverImage]; data['image_list'] = [coverImage];
} }
@@ -70,19 +96,19 @@ class GoodsDetailsPageRepository {
} else { } else {
try { try {
if (!EmptyUtil.isEmpty(_parentGoodsCoverImg) && !EmptyUtil.isEmpty(data) && !EmptyUtil.isEmpty(data['image_list'])) { if (!EmptyUtil.isEmpty(_parentGoodsCoverImg) && !EmptyUtil.isEmpty(data) && !EmptyUtil.isEmpty(data['image_list'])) {
if(data['image_list'][0] != _parentGoodsCoverImg) {
if (data['image_list'][0] != _parentGoodsCoverImg) {
data['image_list'].insert(0, _parentGoodsCoverImg); data['image_list'].insert(0, _parentGoodsCoverImg);
} }
}else if(!EmptyUtil.isEmpty(_parentGoodsCoverImg) && !EmptyUtil.isEmpty(data) && EmptyUtil.isEmpty(data['image_list'])){
} else if (!EmptyUtil.isEmpty(_parentGoodsCoverImg) && !EmptyUtil.isEmpty(data) && EmptyUtil.isEmpty(data['image_list'])) {
data['image_list'] = [_parentGoodsCoverImg]; data['image_list'] = [_parentGoodsCoverImg];
} }
}catch(e, s){
} catch (e, s) {
Logger.error(e, s); Logger.error(e, s);
} }
} }
} }


Map<String, dynamic> style =!EmptyUtil.isEmpty(item['style']) ? jsonDecode(item['style']) : new Map<String, dynamic>();
Map<String, dynamic> style = !EmptyUtil.isEmpty(item['style']) ? jsonDecode(item['style']) : new Map<String, dynamic>();
style.addAll(baseData); style.addAll(baseData);


if (!EmptyUtil.isEmpty(data)) { if (!EmptyUtil.isEmpty(data)) {
@@ -101,5 +127,4 @@ class GoodsDetailsPageRepository {
} }
return null; return null;
} }

} }

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

@@ -58,7 +58,7 @@ class _CounponWidgetContainerState extends State<CounponWidgetContainer> {


/// 点击领取 /// 点击领取
void _onJump(CounponModel model) async{ void _onJump(CounponModel model) async{
TurnChainUtil.openReceiveCoupon(context, _user, model.provider, model?.convertArgs?.toJson());
TurnChainUtil.openReceiveCoupon(context, _user, model?.good_id, model.provider, model?.convertArgs?.toJson());
} }


@override @override


+ 12
- 8
lib/widgets/goods_details/coupon/model/counpon_model.dart View File

@@ -11,11 +11,12 @@ class CounponModel {
String price_type_color; String price_type_color;
String buy_url; String buy_url;
String provider; String provider;
String goood_id;
String good_id;
ConvertArgs convertArgs; ConvertArgs convertArgs;
String commission;


CounponModel({ CounponModel({
this.goood_id,
this.good_id,
this.provider, this.provider,
this.bg_img, this.bg_img,
this.coupon_endtime, this.coupon_endtime,
@@ -29,11 +30,12 @@ class CounponModel {
this.price_type_color, this.price_type_color,
this.buy_url, this.buy_url,
this.convertArgs, this.convertArgs,
this.commission,
}); });


factory CounponModel.fromJson(Map<String, dynamic> json) { factory CounponModel.fromJson(Map<String, dynamic> json) {
return CounponModel( return CounponModel(
goood_id: json['goood_id'],
good_id: json['good_id'],
provider: json['provider'], provider: json['provider'],
bg_img: json['bg_img'], bg_img: json['bg_img'],
coupon_endtime: json['coupon_endtime'], coupon_endtime: json['coupon_endtime'],
@@ -47,7 +49,7 @@ class CounponModel {
price_type_color: json['price_type_color'], price_type_color: json['price_type_color'],
buy_url: json['buy_url'], buy_url: json['buy_url'],
convertArgs: json['convert_args'] != null ? ConvertArgs.fromJson(json['convert_args']) : null, convertArgs: json['convert_args'] != null ? ConvertArgs.fromJson(json['convert_args']) : null,
commission: json['commission'],
); );
} }


@@ -65,11 +67,11 @@ class CounponModel {
data['price_type_color'] = this.price_type_color; data['price_type_color'] = this.price_type_color;
data['buy_url'] = this.buy_url; data['buy_url'] = this.buy_url;
data['provider'] = this.provider; data['provider'] = this.provider;
data['goood_id'] = this.goood_id;
data['good_id'] = this.good_id;
if (this.convertArgs != null) { if (this.convertArgs != null) {
data['convert_args'] = this.convertArgs.toJson(); data['convert_args'] = this.convertArgs.toJson();
} }
data['commission'] = this.commission;
return data; return data;
} }
} }
@@ -81,8 +83,9 @@ class ConvertArgs {
String couponPrice; String couponPrice;
String activityUrl; String activityUrl;
String isShare; String isShare;
String commission;


ConvertArgs({this.gid, this.goodUrl, this.couponUrl, this.couponPrice, this.activityUrl, this.isShare});
ConvertArgs({this.gid, this.goodUrl, this.couponUrl, this.couponPrice, this.activityUrl, this.isShare, this.commission});


ConvertArgs.fromJson(Map<String, dynamic> json) { ConvertArgs.fromJson(Map<String, dynamic> json) {
gid = json['gid']; gid = json['gid'];
@@ -91,6 +94,7 @@ class ConvertArgs {
couponPrice = json['coupon_price']; couponPrice = json['coupon_price'];
activityUrl = json['activity_url']; activityUrl = json['activity_url'];
isShare = json['is_share']; isShare = json['is_share'];
commission = json['commission'];
} }


Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@@ -101,7 +105,7 @@ class ConvertArgs {
data['coupon_price'] = this.couponPrice; data['coupon_price'] = this.couponPrice;
data['activity_url'] = this.activityUrl; data['activity_url'] = this.activityUrl;
data['is_share'] = this.isShare; data['is_share'] = this.isShare;
data['commission'] = this.commission;
return data; return data;
} }
} }


+ 3
- 7
lib/widgets/goods_details/footer/goods_details_footer_widget.dart View File

@@ -116,7 +116,7 @@ class _GooddsDetailsFooterContainerState extends State<GooddsDetailsFooterContai
// builder: (context) => GoodsSharePage(widget.model))); // builder: (context) => GoodsSharePage(widget.model)));
// } // }


Map<String, dynamic> result = await TurnChainUtil.getShareTurnChain(context, _user, model.provider, model.convertArgs.toJson());
Map<String, dynamic> result = await TurnChainUtil.getShareTurnChain(context, _user, model?.good_id, model.provider, model.convertArgs.toJson());
if (!EmptyUtil.isEmpty(result)) { if (!EmptyUtil.isEmpty(result)) {
model.shareUrlArgs.buyUrl = result['open_app_url']; model.shareUrlArgs.buyUrl = result['open_app_url'];
Navigator.of(context).push(CupertinoPageRoute(builder: (context) => GoodsSharePage(model.toJson()))); Navigator.of(context).push(CupertinoPageRoute(builder: (context) => GoodsSharePage(model.toJson())));
@@ -125,7 +125,7 @@ class _GooddsDetailsFooterContainerState extends State<GooddsDetailsFooterContai


/// 自购省 /// 自购省
void _saveMoneyOnClick(GoodsDetailsFooterModel model) async { void _saveMoneyOnClick(GoodsDetailsFooterModel model) async {
await TurnChainUtil.openReceiveCoupon(context, _user, model?.provider, model?.convertArgs?.toJson());
await TurnChainUtil.openReceiveCoupon(context, _user, model?.good_id, model?.provider, model?.convertArgs?.toJson());
} }


@override @override
@@ -240,11 +240,7 @@ class _GooddsDetailsFooterContainerState extends State<GooddsDetailsFooterContai
TextSpan( TextSpan(
text: model?.share_value ?? '0.0', text: model?.share_value ?? '0.0',
style: TextStyle( style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: HexColor.fromHex(model?.share_earn_color ?? '#FFFFFF'),
fontFamily: 'Din',
package: 'zhiying_base_widget')),
fontSize: 15, fontWeight: FontWeight.bold, color: HexColor.fromHex(model?.share_earn_color ?? '#FFFFFF'), fontFamily: 'Din', package: 'zhiying_base_widget')),
]), ]),
), ),
Text( Text(


+ 4
- 1
lib/widgets/goods_details/footer/model/goods_details_footer_model.dart View File

@@ -242,8 +242,9 @@ class ConvertArgs {
String couponPrice; String couponPrice;
String activityUrl; String activityUrl;
String isShare; String isShare;
String commission;


ConvertArgs({this.gid, this.goodUrl, this.couponUrl, this.couponPrice, this.activityUrl, this.isShare});
ConvertArgs({this.gid, this.goodUrl, this.couponUrl, this.couponPrice, this.activityUrl, this.isShare, this.commission});


ConvertArgs.fromJson(Map<String, dynamic> json) { ConvertArgs.fromJson(Map<String, dynamic> json) {
gid = json['gid']; gid = json['gid'];
@@ -252,6 +253,7 @@ class ConvertArgs {
couponPrice = json['coupon_price']; couponPrice = json['coupon_price'];
activityUrl = json['activity_url']; activityUrl = json['activity_url'];
isShare = json['is_share']; isShare = json['is_share'];
commission = json['commission'];
} }


Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@@ -262,6 +264,7 @@ class ConvertArgs {
data['coupon_price'] = this.couponPrice; data['coupon_price'] = this.couponPrice;
data['activity_url'] = this.activityUrl; data['activity_url'] = this.activityUrl;
data['is_share'] = this.isShare; data['is_share'] = this.isShare;
data['commission'] = this.commission;
return data; return data;
} }
} }

Loading…
Cancel
Save