avoid_empty_spread
v0.8.0 Warning Fix Collection Type
This rule flags a spread element whose operand is an empty collection literal — ...[], ...{}, ...<int>[].
Why use this rule
Section titled “Why use this rule”Spreading an empty literal contributes nothing to the surrounding collection. It is dead syntax, usually left behind after a refactor removed the elements, or written as a placeholder that was never filled in.
Beyond the noise, it misleads: a reader scanning a widget’s children sees a spread and assumes something conditional is happening there.
Column( children: [ const Header(), // Contributes nothing ...[], const Footer(), ],)Column( children: [ const Header(), const Footer(), ],)If the spread was a placeholder for conditional content, make the condition explicit:
Column( children: [ const Header(), if (showDetails) const Details(), const Footer(), ],)Known limitations
Section titled “Known limitations”Only literal empty collections are reported. A spread of a variable that happens to be empty at runtime (...items) is never flagged, since emptiness is not knowable at analysis time. Null-aware spreads of a variable (...?items) are likewise left alone.
Configuration
Section titled “Configuration”This rule is in the recommended preset, so it is on with
preset: recommended or preset: opinionated. Add it to preset: core with
avoid_empty_spread: true.
To turn it off:
rules: avoid_empty_spread: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_accessing_collections_by_constant_index— Avoid accessing a collection by a constant index inside a loop.avoid_collection_equality_checks— Avoid comparing collections with == or != as it checks reference equality, not contents.avoid_collection_methods_with_unrelated_types— Avoid calling collection methods with arguments whose types are unrelated to the collection’s type parameter.avoid_duplicate_collection_elements— Don’t repeat the same element in a collection literal.