问题描述
升级 flutter(主版本和稳定版本)和 dart 后,我收到一个错误,提示我在项目中使用的各种 for-loops 没有启用实验 --flow-control-collections.我尝试使用
我使用的每个 for 循环都会出现这个错误.
这是我的 flutter --version 结果:
稳定:Flutter 1.12.13+hotfix.5 • 通道稳定 • https://github.com/flutter/flutter.git框架 • 修订版 27321ebbad(13 天前) • 2019-12-10 18:15:01 -0800引擎 • 修订版 2994f7e1e6工具 • Dart 2.7.0掌握:Flutter 1.13.6-pre.16 • 频道主 • https://github.com/flutter/flutter.git框架 • 修订版 fcaf9c4070(2 天前) • 2019-12-21 14:03:01 -0800引擎 • 修订版 33813929e3工具 • Dart 2.8.0(构建 2.8.0-dev.0.0 886615d0f9)
任何想法如何解决这个问题?
嘿,今天早上我遇到了同样的问题,但找到了解决方法.
1) 使用以下代码将 analysis_options.yaml 保存在您的根文件夹中:
分析器:启用实验:- 控制流集合
2) 不要在 for 循环之间使用方括号 {}例如:
[for(类别中的最终类别)CategoryWidget(类别:类别)],
3) 重要的一步,这可能是它对您不起作用的原因:将根文件夹中 pubspec.yml 文件中的 Dart 版本约束更改为 2.5.2
环境:sdk:>=2.5.2
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.
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?
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 loopsEx:
<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"
这篇关于flutter --flow-control-collections 是需要的,但是是吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!