How to show/hide widgets programmatically in Flutter


In Android, every single View subclass has a setVisibility() method that allows you modify the visibility of a View object

There are 3 options of setting the visibility:

  • 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

Is there something equivalent to the above for Widgets in Flutter?

For a quick reference:


UPDATE: Since this answer was written, Visibility was introduced and provides the best solution to this problem.

You can use Opacity with an opacity: of 0.0 to draw make an element hidden but still occupy space.

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 quick tutorial on Opacity:

Answered By – Collin Jackson

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.