Flutter Wrap + List.generate网格布局

本文介绍如何在Flutter中利用Wrap组件结合List.generate方法,实现灵活的网格布局效果。通过调整参数,你可以轻松创建不同列数的响应式网格,适应不同设备屏幕尺寸。

int _selectPosition = -1;
List<ExpUserCellList> _latticeList = [];
Container(
      alignment: Alignment.topCenter,
      margin: EdgeInsets.only(top: 60.w),
      child: Wrap(
        crossAxisAlignment: WrapCrossAlignment.start,
        alignment: WrapAlignment.start,
        spacing: 20.w,
        runSpacing: 20.w,
        children: List.generate(_latticeList.length, (index) {
          return GestureDetector(
            child: Container(
              alignment: Alignment.center,
              width: Utils().screenWidth(context) * 0.22,
              height: 68.w,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(5),
                  color: _selectPosition == index?Colors.white:JadeColors.grey_5,
                  border: Border.all(width: 1,color: _selectPosition == index?JadeColors.blue_2:JadeColors.grey_5)
              ),
              child: Text('${_latticeList[index].num}${S.current.grid}',style: TextStyle(color: _selectPosition == index?JadeColors.blue_2 : _latticeList[index].cellPublishStatus == 0?JadeColors.grey_7:JadeColors.grey_2,fontSize: setFontSize(28),fontWeight: FontWeight.w600),),
            ),
            onTap: () {
              if(_latticeList[index].cellPublishStatus== 0){
                return;
              }
              setState(() {
                _selectPosition = index;
              });
            },
          );
        }),
      ),
    )
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值