You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
246 lines
8.9 KiB
246 lines
8.9 KiB
import 'package:flutter/material.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/retrofit/data/goods.dart'; |
|
import 'package:huixiang/utils/flutter_utils.dart'; |
|
import 'package:huixiang/utils/font_weight.dart'; |
|
import 'package:huixiang/view_widget/custom_image.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:huixiang/view_widget/no_data_view.dart'; |
|
|
|
class PointGoods extends StatefulWidget { |
|
final List<Goods> goods; |
|
final ValueChanged onTap; |
|
|
|
PointGoods(this.goods, this.onTap); |
|
|
|
@override |
|
State<StatefulWidget> createState() { |
|
return _PointGoods(); |
|
} |
|
} |
|
|
|
class _PointGoods extends State<PointGoods> { |
|
String pointPrice(Goods goods) { |
|
if (goods == null) return ""; |
|
if (goods?.oneBean != null && goods?.oneBean != "0") { |
|
return "${goods?.oneBean}印章"; |
|
} |
|
if (goods?.onePrice != null && goods?.onePrice != "0") { |
|
return S.of(context).jifen_(goods?.onePrice); |
|
} else if ((goods?.onePrice == null || goods?.onePrice == "0") && |
|
((goods?.price != null && goods?.price != "0") || |
|
(goods?.money != null && goods?.money != "0.00"))) { |
|
return (goods?.price == "0" || goods?.price == null |
|
? "" |
|
: S.of(context).jifen_(goods?.price)) + |
|
(goods?.money == "0" || goods?.money == null |
|
? "" |
|
: " + ${AppUtils.calculateDouble(double.tryParse(goods?.money) ?? 0)}元"); |
|
} else if (goods.oneMoney != null && goods.oneMoney != "0.00") { |
|
return "${AppUtils.calculateDouble(double.tryParse(goods.oneMoney) ?? 0)}元"; |
|
} else { |
|
return ""; |
|
} |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Container( |
|
// decoration: BoxDecoration( |
|
// borderRadius: BorderRadius.circular(4), |
|
// color: Colors.white, |
|
// ), |
|
// margin: EdgeInsets.only(top: 16.h,right: 14.w,left: 14.w), |
|
child:(widget.goods == null || widget.goods.length == 0) |
|
? NoDataView( |
|
src: "assets/image/xiao_fei.webp", |
|
isShowBtn: false, |
|
text: "当前分类暂无商品", |
|
fontSize: 16.sp, |
|
margin: EdgeInsets.all(60.h), |
|
) |
|
: GridView.builder( |
|
itemCount: widget.goods == null ? 0 : widget.goods.length, |
|
padding: EdgeInsets.only( |
|
left: 16.w, |
|
right: 16.w, |
|
top: 18.h, |
|
bottom: 16.h, |
|
), |
|
shrinkWrap: true, |
|
physics: NeverScrollableScrollPhysics(), |
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( |
|
//一行的Widget数量 |
|
crossAxisCount: 2, |
|
//水平子Widget之间间距 |
|
crossAxisSpacing: 11.w, |
|
//垂直子Widget之间间距 |
|
mainAxisSpacing: 16.w, |
|
//子Widget宽高比例 0.59 |
|
childAspectRatio: |
|
200 / (285 / 2 + (285 / 2) * AppUtils.textScale(context)), |
|
), |
|
itemBuilder: (context, index) { |
|
return GestureDetector( |
|
onTap: () { |
|
widget.onTap(index); |
|
}, |
|
child: buildItem(widget.goods[index]), |
|
); |
|
}, |
|
), |
|
); |
|
} |
|
|
|
Widget buildItem(Goods goods) { |
|
return Container( |
|
alignment: Alignment.center, |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.circular(4), |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Colors.black.withAlpha(12), |
|
offset: Offset(0, 3), |
|
blurRadius: 14, |
|
spreadRadius: 0, |
|
) |
|
], |
|
color: Colors.white, |
|
), |
|
child: Stack( |
|
alignment: AlignmentDirectional.topEnd, |
|
fit: StackFit.loose, |
|
children: [ |
|
Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
mainAxisSize: MainAxisSize.max, |
|
children: [ |
|
MImage( |
|
goods.mainImgPath, |
|
aspectRatio: 158 / 158, |
|
radius: BorderRadius.only( |
|
topLeft: Radius.circular(6), |
|
topRight: Radius.circular(6), |
|
), |
|
fit: BoxFit.cover, |
|
errorSrc: "assets/image/default_1.webp", |
|
fadeSrc: "assets/image/default_1.webp", |
|
), |
|
Expanded( |
|
child: Container( |
|
margin: EdgeInsets.only( |
|
left: 12.w, |
|
right: 12.w, |
|
top: 10.h, |
|
), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Expanded( |
|
child: Text( |
|
goods.name, |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 1, |
|
style: TextStyle( |
|
color: Color(0xff353535), |
|
fontWeight: MyFontWeight.medium, |
|
fontSize: 15.sp, |
|
), |
|
)), |
|
SizedBox( |
|
height: 5.h, |
|
), |
|
Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
pointPrice(goods), |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 2, |
|
style: TextStyle( |
|
color: Color(0xFFE5600D), |
|
fontSize: 15.sp, |
|
fontFamily: 'JDZhengHT', |
|
fontWeight: MyFontWeight.semi_bold, |
|
), |
|
), |
|
// Row( |
|
// children: [ |
|
// Image.asset( |
|
// "assets/image/green_leaf.webp", |
|
// fit: BoxFit.cover, |
|
// width: 12, |
|
// height: 12, |
|
// ), |
|
// Text( |
|
// "x100", |
|
// overflow: TextOverflow.ellipsis, |
|
// maxLines: 2, |
|
// style: TextStyle( |
|
// color: Color(0xFF32A060), |
|
// fontWeight: MyFontWeight.semi_bold, |
|
// fontSize: 15.sp, |
|
// ), |
|
// ), |
|
// ], |
|
// ), |
|
], |
|
) |
|
// Row( |
|
// mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
// crossAxisAlignment: CrossAxisAlignment.end, |
|
// children: [ |
|
// Expanded( |
|
// child: Text( |
|
// S.of(context).yuan_(goods.worth), |
|
// style: TextStyle( |
|
// color: Color(0xFF585858), |
|
// decoration: TextDecoration.lineThrough, |
|
// decorationColor: Color(0xFF585858), |
|
// fontWeight: MyFontWeight.regular, |
|
// fontSize: 12.sp, |
|
// ), |
|
// ), |
|
// flex: 1, |
|
// ), |
|
// Text( |
|
// "库存:${goods?.stock ?? goods?.stock ??""}份", |
|
// style: TextStyle( |
|
// color: Color(0xFF585858), |
|
// decorationColor: Color(0xFF353535), |
|
// fontWeight: MyFontWeight.medium, |
|
// fontSize: 12.sp, |
|
// ), |
|
// ), |
|
// ], |
|
// ), |
|
], |
|
), |
|
), |
|
flex: 1, |
|
), |
|
SizedBox( |
|
height: 10.h, |
|
), |
|
], |
|
), |
|
// Visibility( |
|
// visible: goods.isHot, |
|
// child: ClipRRect( |
|
// borderRadius: BorderRadius.only(topRight: Radius.circular(4)), |
|
// child: Image.asset( |
|
// "assets/image/icon_hot_right_top.webp", |
|
// width: 36, |
|
// height: 36, |
|
// fit: BoxFit.cover, |
|
// ), |
|
// ), |
|
// ), |
|
], |
|
), |
|
); |
|
} |
|
}
|
|
|