Flutter - How to enable control-flow-collection? - flutter

I'm trying use control-flow-collections in Flutter(Google's UI toolkit) to enable the use of inline for loop, i.e:
for (int i = 0; i < globals.currentScaleList.scales.length; i++)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
globals.currentScaleList.scales[i].scaleType.toString(),
style: TextStyle(fontSize: 20.0),
),
],
),
], itemExtent: 23.0, onSelectedItemChanged: (index) {}),
I have seen the other questions on the topics in SO and followed all of the instructions that seem to work for others.
I am running Flutter 1.15.4-pre.248 on the Master channel and Dart 2.8.0
Flutter 1.15.4-pre.248 • channel master • https://github.com/flutter/flutter.git
Framework • revision 686d163420 (2 hours ago) • 2020-03-02 16:25:22 -0500
Engine • revision 5e474ee860
Tools • Dart 2.8.0 (build 2.8.0-dev.10.0 fbe9f6115d)
I have created a analysis_options.yaml file in my root app folder and added the following:
analyzer:
enable-experiment:
- control-flow-collections
I have also updated the min version of Dart in my pubspec.yaml, i.e.:
environment:
sdk: ">=2.5.0 <3.0.0"
However, I still get the error against my 'for' loop stating:
"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."
When I do enable the 3 lines in my analysis_options.yaml file, I get the warning:
"The option 'control-flow-collection' isn't supported by 'enable-experiment'."
What am I missing? Thanks

For those who are facing this issue and have tried creating the analysis_options.yaml, I did what Paul Toal said on the last comment.
Remove analysis_options.yaml (if created)
Run flutter clean command
Restart VSCode
This one worked for me, using the following.
environment:
sdk: ">=2.5.2 <3.0.0"

I had the same issue with the moor_database.g.dart, the Moor generated file. I got it fixed by:
1- Upgrading the sdk constraints with the following
environment:
sdk: ">=2.8.0 <3.0.0"
2- On DartAnalysis in the Android Studio, click on Restart Dart Analysis Server, the first icon button on top left of the DartAnalysis window.
Weird, but worked.

Related

Dart get won't run

I am facing a problem that really isn't making any sense, a problem that started when I wanted to use the "http" and "provide" dependencies by entering them into the pubspec.yaml file.
pub get won't run due to the dart version being lower than 2.16.1 even though when I run dart --version it informs me that I do have the latest dart version (2.16.1).
I tried finding answers on the internet including on the https://dart.dev/ site. I really don't know what else to do at this point, as this is for my assignment due on the 25th of March 2022. please help.
In your pubspec.yaml, just above where your screenshot cuts off, there is a line that looks like this.
environment:
sdk: ">=2.14.0 <3.0.0"
Update this to the following:
environment:
sdk: ">=2.16.1 <3.0.0"
You updated Dart on your local machine, but you never updated your project to reflect that it should use this version (or a higher version).

Error when reading 'migrate': No such file or directory

I want to use migration tool as described here.
But I get Error: Error when reading 'migrate': No such file or directory
Here my dart version and error
xxx#xxx-:~/Desktop/xxx$ dart --version
Dart VM version: 2.4.0 (Unknown timestamp) on "linux_x64"
xxx#xxx-I:~/Desktop/xxx$ dart migrate
Error: Error when reading 'migrate': No such file or directory
pubspec.yaml
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
**
First solution :**
dart --version
If the dart sdk version is less than 2.12.0
Then try:
Flutter upgrade --force
or
dart upgrade
If dart migrate still doesn'tt work then jump to the second solution
Second solution :
since dart is already downloaded as part of flutter
Make sure first that it hasn't been downloaded twice
on Mac try :
where dart
on MS windows , check your path in the environment variables.
If there was more than one path for the dart sdk , then this is problem
In my case I had it installed twice
/usr/local/bin/dart
/Users/USER/Documents/flutter/bin/dart
so I removed the first one by (mac os)
rm /usr/local/bin/dart
The moment I did that the issue was fixed.
Try
dart --version
again and you should be having the latest version of dart that comes with flutter and you should be able to run succsfully
dart migrate

'Flutter/Flutter.h' file not found webview_flutter-1.0.7

Please help me! I don't know what is that problem but I think is since I updated to the latest version of flutter.
I tried with , flutter clean, rm podfile, and more !! but I can't fix that ,is problem from flutter?
I have two days trying to repair it, but I have not been successful.
*I update all my pods, I did all!, but I can't do that work.. (flutter doctor its ok)
my flutter version is
**I tried that in channel stable too, but not worked.
Flutter 1.26.0-2.0.pre.157 • channel master • https://github.com/flutter/flutter.git
Framework • revision 4b83be6c23 (9 hours ago) • 2020-12-30 02:09:03 -0500
Engine • revision 0e5a25d779
Tools • Dart 2.12.0 (build 2.12.0-179.0.dev)
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
In file included from /Users/victormanuellagunas/Documents/development/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-1.0.7/ios/Classes/JavaScriptChannelHandler.m:5:
/Users/victormanuellagunas/Documents/development/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-1.0.7/ios/Classes/JavaScriptChannelHandler.h:5:9: fatal error: 'Flutter/Flutter.h' file not found
#import <Flutter/Flutter.h>
^~~~~~~~~~~~~~~~~~~
1 error generated.
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
Could not build the application for the simulator.
Error launching application on iPhone 12 Pro Max.
I had the same Problem and solved it with these Steps:
go to this Directory /Users/victormanuellagunas/Documents/development/flutter/.pub-cache/hosted/pub.dartlang.org
Delete the webview_flutter-1.0.7 Folder
Then run following command in project folder.
flutter pub get
If this is not working the try to use a lower Version for example 1.0.6

How to fix "This requires the spread-collection experiment to be enable " on latest upgrade of flutter?

Hello I have a code like this
SizedBox(height: 10),
..._function(context, model),
SizedBox(height: 5),
if (model.bloc)
)
But after flutter upgrade I have error focus on "..."
This requires the spread-collection experiment to be enable
How can I rewrite this correctly ? Thank you
In pubspec.yaml
change environment sdk constraints to:
sdk: ">=2.7.0 <3.0.0"
Invalidate Caches and Restart your IDE
Android Studio: File>> Invalidate Caches and Restart.
That would be enough.
What happens when you change your environment to this:
environment:
sdk: ">=2.6.0 <3.0.0"
and also do a Flutter clean and restart the IDE
Edited:
In the root of your project create a file named analysis_options.yaml and add these lines to it:
analyzer:
enable-experiment:
- spread-collections

Flutter app Error while initializing the Dart VM: Wrong full snapshot version, expected '8343.....' found '46b2....'

flutter app was working getting build and run on Xcode 10 on device iOS 12 fine before,
The time dart upgrade 2.1.0 happen in Flutter build iOS worked well with command and on Xcode 10 after build get success while running Flutter app on iPhone 7 iOS 12, it started giving error and app gets crash with following error message in Xcode logs.
Error is Runner[410:28754] [VERBOSE-3:dart_vm.cc(403)] Error while initializing the Dart VM: Wrong full snapshot version, expected '8343f188ada07642f47c56e518f1307c' found '46b2bfb57b5647c5f7527ff9aa56c69b'
Here are the details of the flutter sdk and dart .
Flutter 0.11.9 • channel beta • https://github.com/flutter/flutter.git
Framework • revision d48e6e4
Engine • revision 5c8147450d
Tools • Dart 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)
I have experienced this error and none of the above solution worked for me infact the option of clearing the flutter/bin/cache messed the entire vscode IDE.
So I deleted the entire flutter SDK and installed fresh new SDK from flutter official website.
After this installation everything was working fine.
I had this issue after a flutter upgrade. Uninstalling the app from the device and then flutter running it again solved the problem.
After deleting the flutter/bin/cache and running flutter clean, I couldn't get the dart sdk to load until I launched the flutter console (flutter_console.bat) that can be found in the directory where you installed flutter and ran flutter doctor there. That solved the problem.
Do git clean -xffd in flutter installed directory(repo).
If it's a Flutter project first try flutter clean if did not work, try above git command.
If still not solved, delete everything inside /flutter/bin/cache and try.
If still not :D,
Do flutter channel master, flutter upgrade, and flutter clean. If nothing worked please add a comment below.
If you are in Dart environment out flutter/bin/cach/dart-sdk, you may be not upgraded dart-sdk. This happen to me Dart 2.5.0 with chololate installed. So I just did choco upgrade dart-sdk
I have exactly this problem i Solve it how ?
by these comments you just update flutter
flutter channel beta
,
flutter upgrade
you should upgrade your dart sdk
So try this command :
choco install dart-sdk
if this is not work for you download it from this link
https://dart.dev/tools/sdk/archive;
and replace it with your current dart-sdk in flutter
I also have experienced the same issue. I upgraded the flutter version and later downgraded and encounter this issue maily on IOS adhoc build.
Solution:
Delete out $FLUTTER_HOME/bin/cache and run flutter doctor.
This will solve.
What worked for me was changing channel and upgrading and then changing channel back and upgrading.
I had to remove the flutter SDK folder in my computer completely and redownload the latest one at https://flutter.dev/docs/get-started/install/macos
Then, I ran flutter doctor.
You can find where your flutter folder is by typing which flutter in your terminal.
You don't need to uninstall the whole flutter and set environment path or anything else.
Just downgrade to any version by doing the below commands, suppose my current flutter version is v3.3.8 and I come across this issue then:
Go to flutter sdk-path in the command prompt and checkout to any branch you would like to switch for a moment, like v2.5.0. So,
By doing this you changed your repository from v3.3.8 to v2.5.0
git checkout v2.5.0
You can check previous flutter versions from here
link
Downgrade your flutter version to 2.5.0
flutter downgrade v2.5.0
Then upgrade flutter
flutter upgrade