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; final ValueChanged onTap; PointGoods(this.goods, this.onTap); @override State createState() { return _PointGoods(); } } class _PointGoods extends State { @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, style: TextStyle( color: Color(0xff353535), fontWeight: MyFontWeight.medium, fontSize: 16.sp, ), ), SizedBox( height: 5.h, ), Container( height: 35.h * AppUtils.textScale(context), child: Text( goods.description, maxLines: 2, overflow: TextOverflow.ellipsis, style: TextStyle( color: Color(0xFF727272), fontWeight: MyFontWeight.regular, fontSize: 12.sp, ), ), ), 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( S.of(context).jifen_(goods.price), style: TextStyle( color: Color(0xFF32A060), fontSize: 14.sp, fontWeight: MyFontWeight.semi_bold, ), ), ], ), ], ), ), 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, ), ), ), ], ), ); } }