Conditionally place a widget in Flutter


We have already seen ( errorText example ) that how to use conditional express in Flutter.

I want to place an Icon in a widget ListView or what ever want to be which is changing based on some condition, say, Show a cloud Icon when I synced the data otherwise just show a regular offline Icons.

How to conditionally place a cloud icon inside a Flutter Scaffold or any widget   ?

 

We can use a conditional expression which only accept a bool expression. Let create a bool variable. You can change the value of the variable programmatically almost any event handler or in setState block. 

Then you can write a conditional expression before the placement of widget as follows

isCloud? Icon(Icons.cloud_circle): Icon(Icons.cloud_off)

Simple isn’t. If you interested in the complete project just go ahead

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.