Flutter – This requires the ‘control-flow-collections’ experiment to be enabled. 解决办法

在进行 Flutter 开发的时候有可能遇到这个错误:

This requires the 'control-flow-collections' experiment to be enabled.
Try enabling this experiment by adding it to the command line when compiling and running.

出现这个错误的原因是:在 Dart 2.5 以前的版本,control-flow-collections 还是一个实验版本,并没有正式的去用;但在 Dart 2.5 之后这个功能已经可以正式使用,只需更新 pubspec.yaml中的最低Dart版本就解决了:

environment:
  sdk: ">=2.5.0 <3.0.0"

如果使用的是命令行,则需要重新加载包配置: flutter pub get

【注】Flutter 现在还在不断地更新完善中,建议持续使用新版本,就和苹果的 Swift 一样。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注