Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I enable Flutter/Dart language experiments?

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)
like image 777
Vince Varga Avatar asked Apr 02 '19 14:04

Vince Varga


3 Answers

In my case, I have followed these two steps and It worked for me.

  1. run "flutter upgrade"

  2. changing the sdk in the environment in pubspec.yaml

    environment:   sdk: ">=2.6.0 <3.0.0" 
like image 86
Tasnim Avatar answered Oct 21 '22 12:10

Tasnim


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" 
like image 38
atreeon Avatar answered Oct 21 '22 11:10

atreeon


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.

like image 31
C4s4r Avatar answered Oct 21 '22 11:10

C4s4r