Show/hide widgets in Flutter programmatically
In Android, every single
View subclass has a
setVisibility() method that allows you modify the visibility of a
There are 3 options of setting the visibility:
- Visible: Renders the
Viewvisible inside the layout
- Invisible: Hides the
View, but leaves a gap that is equivalent to what the
Viewwould occupy if it were visible
- Gone: Hides the
View, and removes it entirely from the layout. It's as if its
Is there something equivalent to the above for Widgets in Flutter?
For a quick reference: https://developer.android.com/reference/android/view/View.html#attr_android:visibility
UPDATE: Since this answer was written,
Visibility was introduced and provides the best solution to this problem.
You can use
Opacity with an
0.0 to draw make an element hidden but still occupy space.
To make it not occupy space, replace it with an empty
EDIT: 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: https://youtu.be/9hltevOHQBw