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.

179 lines
5.9 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';
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> {
@override
Widget build(BuildContext context) {
return GridView.builder(
itemCount: widget.goods == null ? 0 : widget.goods.length,
padding: EdgeInsets.only(
left: 16.w,
right: 16.w,
top: 13.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:
166 / (281 / 2 + (281 / 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(
mainAxisSize: MainAxisSize.max,
children: [
MImage(
goods.mainImgPath,
aspectRatio: 1,
radius: BorderRadius.only(
topLeft: Radius.circular(4),
topRight: Radius.circular(4),
),
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.png",
fadeSrc: "assets/image/default_1.png",
),
Expanded(
child: Container(
margin: EdgeInsets.only(
left: 12.w,
right: 12.w,
top: 10.h,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
goods.name,
overflow: TextOverflow.ellipsis,
3 years ago
maxLines: 2,
3 years ago
style: TextStyle(
color: Color(0xff353535),
fontWeight: MyFontWeight.medium,
fontSize: 16.sp,
),
),
SizedBox(
height: 5.h,
),
3 years ago
Text(
(goods?.price == null || goods.price == "0"?"":S.of(context).jifen_(goods.price)) + (goods?.money == null|| goods.money == "0.00" ?"":" + ${goods.money}"),
3 years ago
style: TextStyle(
color: Color(0xFF32A060),
fontSize: 14.sp,
fontWeight: MyFontWeight.semi_bold,
3 years ago
),
),
SizedBox(
height: 4.h,
),
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(
3 years ago
"库存:${goods?.stock ?? goods?.stock ??""}",
3 years ago
style: TextStyle(
3 years ago
color: Color(0xFF585858),
decorationColor: Color(0xFF353535),
fontWeight: MyFontWeight.medium,
fontSize: 12.sp,
3 years ago
),
),
],
),
],
),
),
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.png",
width: 36,
height: 36,
fit: BoxFit.cover,
),
),
),
],
),
);
}
}