prefer_if_elements_to_conditional_expressions

Group: style

Maturity: stable

Dart SDK: >= 2.3.0 • (Linter v0.1.85)

Since info is static, may be stale
has-fix

View all Lint Rules

Using the Linter

When building collections, it is preferable to use if elements rather than conditionals.

BAD:

var list = ['a', 'b', condition ? 'c' : null].where((e) => e != null).toList();

GOOD:

var list = ['a', 'b', if (condition) 'c'];