Inline if assignment instead of ternary operator with null else branch #1714
Labels
feature
Proposed language feature that solves one or more problems
state-duplicate
This issue or pull request already exists
Use case
Many times in Flutter I've found myself writing conditional rendering using ternary operator where "else" branch returns null.
For example, a custom Widget has a parameter that will set some property of the nested widget or even add another widget to the tree.
Within
Column
orRow
(or whenever we use array[]
) it is possible to useif statement
, however elsewhere I am forced to use ternary operator where else does nothing other than returning null.Scaffold
widget with shared settings and I can passdrawerBuilder
to add a drawer to that ScaffoldProposal
Probably this request will need support from dart-lang itself. I am coming from React background and in JS / TS is possible to use
&&
operator for such inline rendering without an explicitelse
branch. E.g, example 2 could be rewritten intoIt is maybe just personal preference, but I found this more clear than cluttering
: null
with a ternary operator.The text was updated successfully, but these errors were encountered: