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.

245 lines
8.8 KiB

3 years ago
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';
3 years ago
import 'package:huixiang/view_widget/no_data_view.dart';
3 years ago
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> {
3 years ago
String pointPrice(Goods goods) {
if (goods == null) return "";
if (goods?.oneBean != null && goods?.oneBean != "0") {
return "${goods?.oneBean}印章";
}
3 years ago
if (goods?.onePrice != null && goods?.onePrice != "0") {
3 years ago
return S.of(context).jifen_(goods?.onePrice);
3 years ago
} 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)}";
3 years ago
}
}
3 years ago
@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);
3 years ago
},
child: buildItem(widget.goods[index]),
3 years ago
);
},
),
);
3 years ago
}
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(
3 years ago
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
3 years ago
mainAxisSize: MainAxisSize.max,
children: [
MImage(
goods.mainImgPath,
3 years ago
aspectRatio: 158 / 158,
3 years ago
radius: BorderRadius.only(
3 years ago
topLeft: Radius.circular(6),
topRight: Radius.circular(6),
3 years ago
),
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.webp",
fadeSrc: "assets/image/default_1.webp",
3 years ago
),
Expanded(
child: Container(
margin: EdgeInsets.only(
left: 12.w,
right: 12.w,
top: 10.h,
),
child: Column(
3 years ago
mainAxisAlignment: MainAxisAlignment.spaceAround,
3 years ago
crossAxisAlignment: CrossAxisAlignment.start,
children: [
3 years ago
Expanded(
child: Text(
3 years ago
goods.name,
overflow: TextOverflow.ellipsis,
3 years ago
maxLines: 1,
3 years ago
style: TextStyle(
color: Color(0xff353535),
fontWeight: MyFontWeight.medium,
3 years ago
fontSize: 15.sp,
3 years ago
),
3 years ago
)),
3 years ago
SizedBox(
height: 5.h,
),
3 years ago
Column(
3 years ago
mainAxisAlignment: MainAxisAlignment.start,
3 years ago
crossAxisAlignment: CrossAxisAlignment.start,
3 years ago
children: [
3 years ago
Text(
3 years ago
pointPrice(goods),
overflow: TextOverflow.ellipsis,
maxLines: 2,
3 years ago
style: TextStyle(
color: Color(0xFFE5600D),
3 years ago
fontSize: 15.sp,
fontFamily: 'JDZhengHT',
3 years ago
fontWeight: MyFontWeight.semi_bold,
3 years ago
),
3 years ago
),
// 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,
// ),
// ),
// ],
// ),
3 years ago
],
)
3 years ago
// 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,
// ),
// ),
// ],
// ),
3 years ago
],
),
),
flex: 1,
),
SizedBox(
height: 10.h,
),
],
),
3 years ago
// 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,
// ),
// ),
// ),
3 years ago
],
),
);
}
}