I want to use the new spread syntax in Dart.
I'm using Android Studio for Flutter development and I receive this error.
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.
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)
In my case, I have followed these two steps and It worked for me.
run "flutter upgrade"
changing the sdk in the environment in pubspec.yaml
environment: sdk: ">=2.6.0 <3.0.0"
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
And also make sure you have a recent enough version of flutter
flutter upgrade
Ensure you are on the right version of flutter and dart that allows that feature by running
flutter --version
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"
With the new version of flutter it became an error - but it can easily be fixed by updating the sdk version:
environment:
sdk: ">=2.7.0 <3.0.0"
Just don't forget to restart VisualStudio Code or whatever IDE you're using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With