Tl;dr: Visit this package and read the “Usage” section.
In Flutter you can do conditional rendering:
You may also conditionally render a list of widgets:
But what if you want to use a tertiary (if-else) condition?
It is okay for a single
Text widget, but the readability quickly become very bad when the child widget is multi-layered.
That’s why I created a package: `flutter_conditional_rendering`
You may also use
ConditionalSwitch.list() if you want to conditionally render a list of widgets:
Conditional.single() function accepts a condition builder and 2 widget builders instead of accepting 1 boolean value and 2 widget variable?
Typically when you decide a condition, you need to: i.e. Get some data from the
provider package), or find some value within a list. Those logic/statements are often related to the condition only, encapsulating them into a builder function makes the code cleaner, and reduces the conscious load while reading the code:
Here is what you should do:
So this is how you should do conditional rendering in your flutter apps.
Now go visit this package, install it and give it a try!