[英]How to hide and show app bar action buttons
我想根据页面的上下文隐藏和显示应用栏操作按钮。 可能需要将IconButton放在另一个小部件中,但是哪个小部件的属性类似于isHidden?
appBar: AppBar(
title: Text("Work Order"),
backgroundColor: Colors.black,
actions: <Widget>[
IconButton(
onPressed: () {},
icon: Icon(Icons.delete),
),
IconButton(
onPressed: () {},
icon: Icon(Icons.add),
),
],
),
更新:
简单的方法是使用空的Container()
appBar: AppBar(
title: Text("Work Order"),
backgroundColor: Colors.black,
actions: <Widget>[
_isDeleteMode ? IconButton(
onPressed: () {},
icon: Icon(Icons.delete) : Container(),
),
IconButton(
onPressed: () {},
icon: Icon(Icons.add),
),
],
),
您可以使用布尔值标记从小部件树中完全删除图标,如下所示:
appBar: AppBar(
title: Text("Work Order"),
backgroundColor: Colors.black,
actions: yourBoolean ? [
IconButton(
onPressed: () {},
icon: Icon(Icons.delete),
),
IconButton(
onPressed: () {},
icon: Icon(Icons.add),
),
] : [],
),
或者,您可以将您的图标包装在不透明度小部件上。
我发现的最简单方法是使用一个空的容器
appBar: AppBar(
title: Text("Work Order"),
backgroundColor: Colors.black,
actions: <Widget>[
_isDeleteMode ? IconButton(
onPressed: () {},
icon: Icon(Icons.delete) : Container(),
),
IconButton(
onPressed: () {},
icon: Icon(Icons.add),
),
],
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.