如何启用 Flutter/Dart 语言实验? [英] How can I enable Flutter/Dart language experiments?
问题描述
我想在 Dart 中使用新的传播语法.
I want to use the new spread syntax in Dart.
我正在使用 Android Studio 进行 Flutter 开发,但收到此错误.
I'm using Android Studio for Flutter development and I receive this error.
这需要启用 --spread-collections 实验
This requires the --spread-collections experiment to be enabled
ListView(children: [...listTiles, MyWidget()])
但是,我没有找到可以指定此选项的任何地方.
However, I didn't find anywhere where I could specify this option.
我什至无法让它在命令行上运行.flutter --spread-collections run
给出 找不到名为spread-collections"的选项.
.
I couldn't even make it work on the command line. flutter --spread-collections run
gives Could not find an option named "spread-collections".
.
flutter --version
Flutter 1.3.8 • channel beta • https://github.com/flutter/flutter.git
Framework • revision e5b1ed7a7f (4 weeks ago) • 2019-03-06 14:23:37 -0800
Engine • revision f4951df193
Tools • Dart 2.2.1 (build 2.2.1-dev.0.0 571ea80e11)
推荐答案
你需要在你的 Flutter 应用的根目录中创建一个 analysis_options.yaml 文件并编写类似的东西
You need to create an analysis_options.yaml file in the root of your flutter app and write something like
analyzer:
enable-experiment:
- spread-collections
还要确保切换到包含新功能的正确频道,例如(开发版、测试版或主版)
Also make sure to switch to the correct channel where the new feature is included eg (dev, beta or master)
flutter channel dev
还要确保你有足够新的 flutter 版本
And also make sure you have a recent enough version of flutter
flutter upgrade
确保您使用的是正确版本的 flutter 和 dart,运行该功能即可
Ensure you are on the right version of flutter and dart that allows that feature by running
flutter --version
您可能还需要手动更改 pubspec.yaml 文件以指定正确的 dart sdk(如果是,请重新运行 flutter upgrade)
you may also have to manually change your pubspec.yaml file to specify the correct dart sdk (if so rerun flutter upgrade)
environment:
sdk: ">=2.10.0-0 <3.0.0"
这篇关于如何启用 Flutter/Dart 语言实验?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!