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: 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 / (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( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ MImage( goods.mainImgPath, aspectRatio: 1.1, 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: [ Text( goods.name, overflow: TextOverflow.ellipsis, maxLines: 2, style: TextStyle( color: Color(0xff353535), fontWeight: MyFontWeight.medium, fontSize: 15.sp, ), ), Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( (goods?.price == null || goods.price == "0"?"":S.of(context).jifen_(goods.price)) + (goods?.money == null|| goods.money == "0.00" ?"":" + ${goods.money}元"), style: TextStyle( color: Color(0xFFE5600D), fontSize: 16.sp, fontWeight: MyFontWeight.semi_bold, ), ), 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: 16.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, // ), // ), // ), ], ), ); } }