Be a flutter ace at managing the visibility of widgets

Janmey Solanki

image

The Flutter framework was designed by Google company teams, like the Android operating system. It, therefore, incorporates new features of the operating system as it is developed. Moreover, an application created with the framework will also work on iOS from the same code. To display or hide a widget, the framework has integrated the same operation found with developing a native application for Android.

There are several ways to hide a widget. You can either hide it entirely or make it invisible, but the space it occupies is still there. With Flutter, both systems are supported through the “Visibility” property, just like a native Android app. The “Visible” attribute allows you to display or hide a widget according to your defined value.

visibility(
child: Text("Fully hidden widget"),
visible: false,
,

Other attributes allow the widget to keep its space while being invisible. The “maintainSize” attribute manages the size, “maintainanimation” takes care of the animation of the widget and “maintainState” takes care of the state. If you set all of these to “true” then the widget is not visible but still in your app and takes up space.

visibility(
child: Text("Invisible but still takes up space"),
maintainSize: true,
maintainAnimation: true,
maintainState: true,
visible: false, ),

If you are working with an older version of the framework, the “Visibility” attribute may not have been integrated yet. In this case, you need to work around the problem. To completely hide a widget and no longer occupy space, replace the container containing it with an empty container. To make it invisible while keeping the space, you can use the “Opacity” property, which controls the opacity of an element and assign a value of 0, which will make it impossible to see. Then move the code of your widget into the “Child” attribute.

new Opacity(opacity: 0.0, child: myWidget)

Was this blog helpful?
1
Having something to say? We are open for feedback here

Looking for hassle free product Development?

imageDiscover impactful development solutions with einfonets and take your business to the next level .

einfonets: Product Engineering Services | Digital Transformation Cloud Solutions

imageFind out five reasons why you should choose einfonets for your next product development.

We always try to be the best support to you as possible

Qualify your leads & recognize the value of word your customer will love you

Contact Us
image
image
image
image
image