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

我与影子孤独终老i 提交于 2020-02-20 08:28:06

问题


After upgrading to flutter 1.13.6(master) and also 1.12.13(stable) with dart 2.8 and 2.7 respectively, 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.

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

Here's my flutter --version

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?


回答1:


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"



回答2:


Simply updating the minimum Dart version in pubspec.yaml was enough for me:

environment:
  sdk: ">=2.5.0 <3.0.0"

In the Dart 2.5 Change Log notes you can see the new option for adding an if element to a collection literal.



来源:https://stackoverflow.com/questions/59458433/flutter-flow-control-collections-are-needed-but-are-they

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!