How to enable --control-flow-collections [duplicate] - dart

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)

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"

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"

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.

You are running an old version of flutter
Spreading is available starting at flutter 1.5 and dart 2.3
Run:
flutter upgrade

Here's some fix you can try out :
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 loops
Ex:
<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 or above.
environment:
sdk: ">=2.5.2 <3.0.0"

The current answer that is working in the latest Flutter 1.17.1 or Dart 2.8.2
Create a analysis_options.yaml in the directory of the pubspec.yaml file
Write this code inside the file:
include: package:pedantic/analysis_options.1.8.0.yaml
linter:
rules:
- prefer_spread_collections
For more information head to this documentation

Something completely different yet the same. Our code was built in Flutter v1.12.13hotfix9. when we did a new installation with flutter 1.17.1 the build broke with a similar error. It seems that the new release of Flutter is not backwards compatible on certain parts.
We fixed the problem by installing the older version.

Run this command from your project's root directory:
dart --enable-experiment=spread-collections lib

After updating the environment in pubspec.yml don't forget restart your IDE
environment:
sdk: ">=2.7.2 <3.0.0"

Related

Connecting IOS firebase app to my flutter app

I am trying to connect a IOS Firebase app to my flutter and the packages I am importing come up with the error "The library 'package:firebase_auth_web/firebase_auth_web.dart' is legacy, and should not be imported into a null safe library.
Try migrating the imported library".
There is more than one problem as per your description and comments.
The easiest solution is to upgrade the dart, flutter, and all the dependencies you are using because it seems that you are using all the things which are older.
First, in your command prompt (terminal), run:
> flutter upgrade
This will upgrade your flutter and dart both. Secondly, run:
> flutter pub upgrade
This will upgrade all the dependencies. Finally, run:
> flutter pub upgrade --major-version
This will also upgrade all the dependencies.
Doing these will make your application up to date with the dependencies. Now, try to run the app again. Most probably it will work, if it doesn't then it might tell you to upgrade your compileSdkVersion in build.gradle to something larger number. If so, upgrade that number in your app>build.gradle file.

Flutter pub get Flutter version mismatch | podfile.lock flutter version mismatch

I have updated my flutter version to 3.0.1 - Reference
I have one existing flutter project. When I hit flutter pub get command, inside ios/Flutter/Flutter.podspec file, it is showing flutter version 1.0.0.
s.version = '1.0.0'
Also in the iOS podfile.lock file is also showing flutter version 1.0.0. I tried updating pod, etc everything but same issue.
PODS:
Flutter (1.0.0)
Why it is showing 1.0.0 instead of 3.0.1. or this is not the correct way to check & update flutter version of existing project?
The flutter version depends on your environment (not the project), so you should be able to just run flutter --version to see which version you're running.
As for the project, it should normally build with any compatible flutter version. If you look at your pubspec.yaml, it should have the environment part which specifies the SDK. It should look something like the following to be compatible with the new Flutter version:
environment:
sdk: '>=2.17.0 <3.0.0'
I think (not entirely sure, though) that the 1.0.0 that you see is the app version, as specified in the pubspec.yaml version (usually right above the environment bit).

Dart | Flutter Package: How to update a Packge Not allowing my development to make progress?

The Following Package has not been updated:
https://pub.dartlang.org/packages/tts
I am getting the same error.
Is there any way I can update or fix this issue on my side to continue https://pub.dartlang.org/packages/tts#-analysis-tab-
Running flutter packages pub upgrade failed with the following output:
ERR: The current Dart SDK version is 2.1.0-dev.1.0.flutter-69fce633b7.
Because tts requires SDK version >=1.8.0 <=2.0.0, version solving failed.
Add this to pubspec.yaml
dependency_overrides:
tts: ^1.0.1
until tts is updated to support Dart 2 final.

How can i change my dart-sdk on VSCode

i have been using flutter recently and i really wanted to use Jaguar for my project. But here is the catch, the flutter sdk brought dart with version 2.0.0-dev-58.0 but jaguar said they need dart sdk with version 2.0.0-dev-65.0
Okay, so i get myself dart with sdk version of 2.1.0-dev.1.0, but my vscode can't seem to recognize that i have installed the sdk.
Any ideas on how to change that?
The Dart Code plugin has a setting dart.sdkPath
The location of the Dart SDK to use for analyzing and executing code.
If blank, Dart Code will attempt to find it from the PATH environment
variable. When editing a Flutter project, the version of Dart included
in the Flutter SDK is used in preference.
There's also dart.sdkPaths which allows quick switching between alternatives.
For Flutter projects, use dart.flutterSdkPath(s)
It's quite easy if you use VSCode:
Clone flutter repo to a new folder:
mkdir ~/flutter_dev
cd ~/flutter_dev
git clone https://github.com/flutter/flutter.git .
Open your workspace preferences and update dart.flutterSdkPath setting:
"settings": {
"dart.flutterSdkPath": "/Users/youruser/flutter_dev"
}
Restart VSCode and you're good to go.
See more info in Dart Code - Quickly Switching Between SDK Versions
I want to add one more things to #Andrey, you can use FVM to install as much as you want versions and channels, it's easy to install and manage versions. It hold all versions on your home directory, I think it's easier than managing with Git.

Facing flutter plugin issue

I'm trying to add flutter_svg: ^0.5.1 in my project pubspec.yaml and facing following issue.
depends on flutter_svg >=0.0.2 which requires Flutter SDK version >=0.3.6 <2.0.0, version solving failed.
You might be able to use something like this to override the dependency:
dependency_overrides:
flutter_svg: '0.5.1'
Open the flutter_console.bat (on window) or flutter_console.sh (on linux) file from your downloaded root flutter folder. This should bring up a terminal running Flutter locally.
Now type flutter upgrade
This should resolve your issue considering its a version compatibility issue.

Resources