以编程方式显示/隐藏Flutter中的小部件 [英] Show/hide widgets in Flutter programmatically

查看:145
本文介绍了以编程方式显示/隐藏Flutter中的小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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 the View would occupy if it were visible
  • Gone: Hides the View, and removes it entirely from the layout. It's as if its height and width were 0dp

在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆