How to fix "This requires the spread-collection experiment to be enable " on latest upgrade of flutter?

Viewed 132

Hello I have a code like this

SizedBox(height: 10),
        ..._function(context, model),
        SizedBox(height: 5),
        if (model.bloc)
)

But after flutter upgrade I have error focus on "..."

This requires the spread-collection experiment to be enable

How can I rewrite this correctly ? Thank you

2 Answers

In pubspec.yaml

change environment sdk constraints to:

  sdk: ">=2.7.0 <3.0.0"

Invalidate Caches and Restart your IDE

Android Studio: File>> Invalidate Caches and Restart.

That would be enough.

What happens when you change your environment to this:

environment:
  sdk: ">=2.6.0 <3.0.0"

and also do a Flutter clean and restart the IDE

Edited:

In the root of your project create a file named analysis_options.yaml and add these lines to it:

analyzer:
  enable-experiment:
    - spread-collections
Related