flutter 隐藏控件 中 Offstage Visibility Opacity 不同

flutter 隐藏且不保留位置组件Offstage

假如仅仅判断是否显示    且不保留位  用 Offstage

  Offstage(
    offstage: 布尔值,    当为true时,将隐藏组件且不保留空间位置
    child: 组件,
 另外

Offstage 和  Positioned 一起使用 要把 Offstage  放Positioned里面,包裹 Positioned 会出现问题
Positioned(
  top: 12.h,
  left: 9,
  child: Offstage(
    offstage: unRead == 0,
    child: Container(
      alignment: Alignment.center,
      constraints: BoxConstraints(maxWidth: 14.w, minWidth: 14.w, minHeight: 14.w, maxHeight: 14.w),
      decoration: BoxDecoration(color: ZColors.textTabColor, borderRadius: BorderRadius.circular(7.w)),
      child: Text(
        unRead > 99 ? '99+' : unRead.toString() ,
        style: pingFangS(10, color: Colors.white),
      ),
    ),
  ),
)

假如仅仅判断是否显示  且保留位置   组件Opacity

body: new Center(
        child: new Opacity(
            opacity: 0.1,
          child: new Container(
            height: 100.0,
            width: 250.0,
            color: Colors.red,
          ),
        ),
      )

假如判断两个控件是否显示那个控件  用  Visibility   replacement 属性就是要显示的另一个控件

Visibility(
  //vip过期 或者数据为空 展示的视图
  replacement: brandItemModel == null
      ? Container()
      : Container(
          child: Image.asset(
            ImgAssets.icon_icon_com,
            scale: 2.1,
          ),
        ),
//vip下要展示的视图
  visible: !DateUtils.timeVipDiss(brandItemModel?.vipEndtime),
  child: Row(
    mainAxisAlignment: MainAxisAlignment.spaceBetween,
    children: [
      Container(
        child: Image.asset(
          ImgAssets.icon_tip_mxt,
          scale: 2.1,
        ),
      ),
      SizedBox(
        width: 5,
      ),
      Text("盟信通认证,真实品牌商家",
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
          style: pingFangM(10, color: Color(0xFF666666))),
      Container(
        child: Image.asset(
          ImgAssets.icon_toward_light,
          scale: 2.5,
        ),
      )
    ],
  ),
)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值