flutter --flow-control-collections are needed, but are they?

William Terrill picture William Terrill · Dec 23, 2019 · Viewed 17.5k times · Source

After upgrading flutter (both master and stable versions) and dart, I get an error about the experiment --flow-control-collections not being enabled for various for-loops that I'm using in the project. I tried to fix it using this entry but that just made things weirder. So, now I have the below error that tells me that I need the control-flow-collections experiement to be enabled while simultaneously telling me that it's no longer required.

 eex

This error comes up for every for-loop that I'm using.

Here's my flutter --version result:

Stable:
Flutter 1.12.13+hotfix.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 27321ebbad (13 days ago) • 2019-12-10 18:15:01 -0800
Engine • revision 2994f7e1e6
Tools • Dart 2.7.0

Master:
Flutter 1.13.6-pre.16 • channel master • https://github.com/flutter/flutter.git
Framework • revision fcaf9c4070 (2 days ago) • 2019-12-21 14:03:01 -0800
Engine • revision 33813929e3
Tools • Dart 2.8.0 (build 2.8.0-dev.0.0 886615d0f9)

Any ideas how to resolve this?

Answer

Alexandre picture Alexandre · Dec 23, 2019

Hey, I had the same issue this morning but found a fix.

1) Keep the analysis_options.yaml in your root folder with this code:

analyzer:
  enable-experiment:
    - control-flow-collections

2) Don't use brackets {} in between your for loops Ex:

<Widget>[
  for (final category in categories) 
    CategoryWidget(category: category)
],

3) Important step which is probably why it's not working for you: Change your Dart version constraint in the pubspec.yml file in your root folder to 2.5.2

environment:
  sdk: ">=2.5.2 <3.0.0"