import 'package:flutter/material.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/data/goods.dart'; import 'package:huixiang/utils/flutter_utils.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/border_text.dart'; import 'package:huixiang/view_widget/custom_image.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; class HomeIntegralStore extends StatefulWidget { final List gooods; HomeIntegralStore(this.gooods); @override State createState() { return _HomeIntegralStore(); } } class _HomeIntegralStore extends State { @override Widget build(BuildContext context) { return Container( margin: EdgeInsets.only( left: 16.5.w, right: 16.5.w, bottom: 20.h, top: 10.h, ), padding: EdgeInsets.only(bottom: 3.h, top: 16.h), 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: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding(padding: EdgeInsets.only(left: 16,bottom: 10),child: Text( S.of(context).dajiadouzaiduihuan, textAlign: TextAlign.end, style: TextStyle( color: Colors.black, fontSize: 16.sp, fontWeight: FontWeight.bold, ), ),), Divider( thickness: 1, color: Color(0xffF2F2F2), ), integralStore(), ], ), ); } Widget integralStore() { return GridView.builder( itemCount: (widget.gooods.length > 2 ? 2 : widget.gooods.length), padding: EdgeInsets.all(13.w), shrinkWrap: true, physics: NeverScrollableScrollPhysics(), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( //一行的Widget数量 crossAxisCount: 2, //水平子Widget之间间距 crossAxisSpacing: 13, //垂直子Widget之间间距 mainAxisSpacing: 16, //子Widget宽高比例 childAspectRatio: AppUtils.textScale(context) > 1 ? (1 - ((AppUtils.textScale(context) - 1))) : 0.85, ), itemBuilder: (context, index) { return GestureDetector( onTap: () { Navigator.of(context).pushNamed('/router/integral_store_page', arguments: {"goodsId": widget.gooods[index].id}); }, child: buildItem(widget.gooods[index]), ); }, ); } Widget buildItem(Goods goods) { return Container( alignment: Alignment.center, child: Column( children: [ MImage( goods.mainImgPath ?? "", aspectRatio: 5 / 3, radius: BorderRadius.circular(4), fit: BoxFit.cover, errorSrc: "assets/image/default_1.webp", fadeSrc: "assets/image/default_1.webp", ), SizedBox( height: 4.h, ), Container( margin: EdgeInsets.only(left: 8.w, right: 8.w), child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox( height: 14.h, ), Row( children: [ Expanded( flex: 1, child: Text( goods.name ?? "", overflow: TextOverflow.ellipsis, style: TextStyle( color: Color(0xff353535), fontWeight: MyFontWeight.regular, fontSize: 14.sp, ), ), ), BorderText( padding: EdgeInsets.all(2.h), text: S.of(context).haowu, fontSize: 12.sp, fontWeight: FontWeight.bold, textColor: Color(0xFF32A060), borderColor: Color(0xFF32A060), borderWidth: 1.w, ), ], ), SizedBox( height: 5.h, ), Text( "${goods.description}", overflow: TextOverflow.ellipsis, maxLines: 2, style: TextStyle( color: Color(0xFF727272), fontSize: 12.sp, fontWeight: MyFontWeight.regular, ), ), ], ), ), ], ), ); } }