flutter TabBar tab设置选中时黑色边框,未选中时灰色(左右滑动切换页面时tab选中效果延迟问题)

在这里插入图片描述

_body(){
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        _goodsTabBar(),
        Expanded(child: _goodsListTabView())
      ],
    );
  }

//商品类别tab
  _goodsTabBar() {
    if(_goodsCategoryList.isNotEmpty){
      return Padding(
          padding: EdgeInsets.only(bottom: 10.w),
          child: TabBar(
            controller: _tabController,
            // tabs的长度超出屏幕宽度后,TabBar,是否可滚动
            isScrollable: true,
            // 设置tab文字的类型
            labelStyle: TextStyle(
                fontSize: 26.sp, letterSpacing: 1),
            // 设置tab选中得颜色
            labelColor: JadeColors.grey_2,
            labelPadding: EdgeInsets.symmetric(horizontal: 10.w),
            // 设置tab未选中的颜色
            unselectedLabelColor: JadeColors.grey,
            // 设置tab未选中时文字的类型
            unselectedLabelStyle: TextStyle(fontSize: 26.sp, letterSpacing: 1),
            indicatorWeight: 0.01,
            indicatorColor: JadeColors.grey_2,
            tabs: _goodsCategoryList.asMap().entries
                .map((entry){
              int index = entry.key;
              ProductSelectGoodsCateBean value = entry.value;
              //AnimatedBuilder配置animation: _tabController.animation,实现在滑动时不显示边框线(减少是视觉上的对比,弱化延迟感),滑动完成显示时看起来舒服些
              return AnimatedBuilder(
                animation: _tabController.animation!,
                builder: (BuildContext context, Widget? child) {
                  bool isSelect = _tabController.animation?.value == index;
                  return Container(
                      padding: EdgeInsets.symmetric(horizontal: 26.w),
                      height: 96.w,
                      decoration: BoxDecoration(
                        color: isSelect ? Colors.white : JadeColors.grey_5,
                        border: isSelect
                            ? Border.all(color: JadeColors.grey_2, width: 1)
                            : null,
                        borderRadius: BorderRadius.circular(15),
                      ),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(value.goodsCategoryParentIdNameByGoods ?? '',style: TextStyle(fontWeight: FontWeight.w600),),
                          if(value.goodsCategoryParentIdByGoods != null)
                            Padding(padding: EdgeInsets.only(top: 5.w),
                                child: Text('用户热购',style: TextStyle(fontSize: 20.sp)))
                        ],
                      )
                  );
                },
              );
            }).toList(),
          ));
    }else{
      return SizedBox.shrink();
    }
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值