以编程方式显示/隐藏Flutter中的小部件 [英] Show/hide widgets in Flutter programmatically
问题描述
在Android中,每个 View
子类都有一个 setVisibility()
方法,该方法可让您修改查看
对象
In Android, every single View
subclass has a setVisibility()
method that allows you modify the visibility of a View
object
设置可见性有3种选择:
There are 3 options of setting the visibility:
- 可见:渲染
视图
在布局内可见 - 不可见:隐藏
视图
,但留下的空隙等于视图
在可见的情况下所占据的空间 - 已消失:隐藏
视图
,并将其完全从布局中删除。好像其高度
和宽度
的高度是0dp
- Visible: Renders the
View
visible inside the layout - Invisible: Hides the
View
, but leaves a gap that is equivalent to what theView
would occupy if it were visible - Gone: Hides the
View
, and removes it entirely from the layout. It's as if itsheight
andwidth
were0dp
在Flutter中有与上述小工具相同的东西吗?
Is there something equivalent to the above for Widgets in Flutter?
对于快速参考:
https://developer.android。 com / reference / android / view / View.html#attr_android:visibility
推荐答案
更新:由于此答案是 Visibility
UPDATE: Since this answer was written, Visibility
was introduced and provides the best solution to this problem.
您可以使用不透明度> code>具有
不透明性:
为 0.0
进行绘制,使元素隐藏但仍占据空间。
You can use Opacity
with an opacity:
of 0.0
to draw make an element hidden but still occupy space.
要使其不占用空间,请用空的 Container()
代替。
To make it not occupy space, replace it with an empty Container()
.
编辑:
进行包装在不透明度对象中,执行以下操作:
To wrap it in an Opacity object, do the following:
new Opacity(opacity: 0.0, child: new Padding(
padding: const EdgeInsets.only(
left: 16.0,
),
child: new Icon(pencil, color: CupertinoColors.activeBlue),
))
关于不透明度的Google Developers快速教程: https://youtu.be/9hltevOHQBw
Google Developers quick tutorial on Opacity: https://youtu.be/9hltevOHQBw
这篇关于以编程方式显示/隐藏Flutter中的小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!