在Android中,每个单独的View子类都有一个setVisibility()方法,允许你修改View对象的可见性
有3个设置可见性的选项:
可见:在布局中显示视图
不可见:隐藏视图,但留下一个空白,相当于视图在可见时所占据的空白
消失:隐藏视图,并将其完全从布局中移除。就好像它的高和宽都是0dp
对于Flutter中的小部件,是否有与上述相同的东西?
快速参考:
https://developer.android.com/reference/android/view/View.html#attr_android:visibility
在flutter 1.5和Dart 2.3中,对于可视性消失,您可以在集合中使用if语句设置可见性,而不必使用容器。
e.g
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('This is text one'),
if (_isVisible) Text('can be hidden or shown'), // no dummy container/ternary needed
Text('This is another text'),
RaisedButton(child: Text('show/hide'), onPressed: (){
setState(() {
_isVisible = !_isVisible;
});
},)
],
)
你可以在你的代码中用一个叫做(Visibility)的新小部件封装任何小部件,这是你想让它不可见的小部件最左边的黄色灯
例如:假设你想让一行不可见:
Click in the lamp and choose (Wrap with widget)
Rename the widget to Visibility
Add the visible property and set it to false
The Child of the newly created widget (Visibility Widget) is the Widget that
you want it to be invisible
Visibility(
visible: false,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
width: 10,
),
Text("Search",
style: TextStyle(fontSize: 20
),),
],
),
),
我希望它能在将来帮助到别人