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,
),
)
],
),
)