How to use Dart 3 Alpha in a Flutter project? - flutter

I've already switch to channel master and running dart --version gives me:
Code Block 1
Dart SDK version: 3.0.0-178.0.dev (dev) (Fri Jan 27 17:53:41 2023 -0800) on "macos_arm64"
However, when I try to use the new syntax for records I get the following:
Code Block 2
This requires the 'records' language feature to be enabled.
Try updating your pubspec.yaml to set the minimum SDK constraint to 3.0.0 or higher, and running 'pub get'.
I tried to change the sdk version value in pubspec to ^3.0.0, but I get this:
Code Block 3
Resolving dependencies...
The current Dart SDK version is 3.0.0-178.0.dev.
Because app requires SDK version 3.0.0, version solving failed. exit code 1
And if I try to set the version to be specifically 3.0.0-178.0.dev then I get the error from code block 2, that is:
This requires the 'records' language feature to be enabled.
Try updating your pubspec.yaml to set the minimum SDK constraint to 3.0.0 or higher, and running 'pub get'.

You can follow these steps.
Step 1: Make sure you are on master branch instead of stable(currently). flutter --version will show something like this or later version
Flutter 3.7.0-29.0.pre.21 • channel master • https://github.com/flutter/flutter.git
Framework • revision 75680ae99e (5 hours ago) • 2023-01-28 08:54:06 -0500
Engine • revision 649362168f
Tools • Dart 3.0.0 (build 3.0.0-179.0.dev) • DevTools 2.20.1
Step 2: config the analyzsis_options.yaml
include: package:flutter_lints/flutter.yaml
analyzer:
enable-experiment:
- records
- patterns
You can check & clone my experimental_project repository.

Related

SDK in pubspec.yaml not same as in flutter --version

I'm trying to set environment sdk version to a higher number but it says that my current SDK is as seen below:
The current Dart SDK version is 2.14.4.
Because demo_app_1 requires SDK version >=2.16.0 <3.0.0, version solving failed.
pub get failed (1; Because demo_app_1 requires SDK version >=2.16.0 <3.0.0, version solving failed.)
exit code 1
When i run flutter --version i get the following:
Flutter 3.1.0-0.0.pre.854 • channel master • https://github.com/flutter/flutter.git
Framework • revision ec20ea80ad (17 hours ago) • 2022-05-21 16:28:06 -0400
Engine • revision 1bfe551d6b
Tools • Dart 2.18.0 (build 2.18.0-142.0.dev) • DevTools 2.13.1
Any help would be much appreciated. Thanks.
See you're confusing two things.
The dart SDK version that's mentioned in pubspec.yaml is for the 'dart'
version to be used in the project, not the flutter version.
Important to note that every dart version is compatible with a corresponding flutter version. The dependency can be loose though.
So in your case Flutter 3.1.0-0.0.pre.854 is the flutter version and 2.18.0 is the dart version. This shows that your flutter 3.1 is compatible with dart 2.18 and is installed, but your project uses 2.14.4
You can check the available list from flutter SDK releases
The problem is that demo_app_1 requires an SDK version >= (higher or equal) 2.16.0 but < (below) 3.0.0. The version you have installed is 3.1.0, which does not fulfill the requirement.
You have two options:
Change your flutter installation version
flutter downgrade <version>
flutter doctor
Change the required SDK version in your pubspec.yaml
Change the environment->sdk value
flutter pub get
After that, the issue should be resolved.
Run flutter downgrade 3.0.0 and check if solved

Requires SDK version >=2.16.0 <3.0.0, version solving failed

The current Dart SDK version is 2.14.4.
Because trackkit requires SDK version >=2.16.0 <3.0.0, version solving failed.
pub finished with exit code 1
My pubspec.yaml :
environment:
sdk: ">=2.16.0 <3.0.0"
after running flutter master:
Flutter is already up to date on channel master
Flutter 2.13.0-0.0.pre.145 • channel master • https://github.com/flutter/flutter.git
Framework • revision de4eb16254 (3 hours ago) • 2022-03-18 06:00:24 -0400
Engine • revision edf31ab695
Tools • Dart 2.17.0 (build 2.17.0-220.0.dev) • DevTools 2.11.4
It shows that my Dart is upgraded to 2.17.0 ? I am still unable to run!
You need to upgrade your Dart SDK with:
flutter upgrade
make sure to edit your environment in pubspec.yaml :
environment:
sdk: ">=2.16.0 <3.0.0"
This issue because of, you may installed multiple version of flutter in you system. And in android studio tools pointed to lower version of flutter location.
First you update flutter.
Then check flutter version. flutter --version Make sure you are upgraded to your specified version.
Then check the location of the framework using which flutter
Then you will get the path like /Applications/flutter/bin/flutter
Then open android studio (in mac) go to android studio preference.
Go to Languages & Frameworks from left menu.
Select flutter under the languages &framework section.
Add correct SDK path under flutter SDK path like - /Applications/flutter
If you add correct SDK path it will show the upgraded version and channel details below of the path.
Then click to apply and ok.
It will solve your issue.

problem with dart-sdk from within flutter

I run flutter upgrade and and I got the following message
C:\Users\lenovo\IdeaProjects\simple>flutter upgrade
Flutter is already up to date on channel stable
Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 18116933e7 (3 weeks ago) • 2021-10-15 10:46:35 -0700
Engine • revision d3ea636dc5
Tools • Dart 2.14.4
but when I try to upgrade the packages including the riverpod which has got to the stable release today
I got the following message
The current Dart SDK version is 2.13.4.
Because simple depends on flutter_riverpod >=1.0.0 which requires SDK version >=2.14.0 <3.0.0, version solving failed.
pub get failed (1; Because simple depends on flutter_riverpod >=1.0.0 which requires SDK version >=2.14.0 <3.0.0, version solving failed.)
I when check the dart sdk in the setting of the editor I'm currently using, the dart sdk is of version 2.13.4
anyone know how to fix this issue ??
Try removing the versions, keep only the dependency names in pubspec.yaml . Then run flutter pub get. It will automatically download all compatible versions.

Unable to build flutter tools

Presently on the master channel, I switched to the beta channel then I run flutter upgrade to find out I can't use Linux as a device, so I switched back to the master branch, I run flutter upgrade. Then I started getting these errors:
Because flutter_tools depends on collection >=1.15.0-nnbd <1.15.0-nullsafety.2
which requires SDK version >=2.9.0-18.0 <=2.9.10, version solving failed.
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (9 tries left)
The current Dart SDK version is 2.10.0-0.0.dev.flutter-a3815b6590.
Flutter Info before switching to the master channel
Flutter 1.18.0-11.1.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 2738a11 (3 months ago) • 2020-05-13 15:24:36 -0700
Engine • revision ef9215ceb2
Tools • Dart 2.9.0 (build 2.9.0-8.2.beta)
I can't presently get any info on the master channel (which I am presently on) cause every time I run any flutter command, it tries to run pub upgrade with keeps giving error.
I am assuming the issue is that Dart SDK
upgraded, if I can roll back to a version compatible with the dependency it should work, or the dependency should be reviewed.
Fixed.
I used git to switched branch to stable, then I run flutter upgrade, it worked fine, but I need to run a Linux app on flutter, so I used git to switch branch to dev, then run flutter upgrade again.

flutter --flow-control-collections are needed, but are they?

After upgrading flutter (both master and stable versions) and dart, I get an error about the experiment --flow-control-collections not being enabled for various for-loops that I'm using in the project. I tried to fix it using this entry but that just made things weirder. So, now I have the below error that tells me that I need the control-flow-collections experiement to be enabled while simultaneously telling me that it's no longer required.
This error comes up for every for-loop that I'm using.
Here's my flutter --version result:
Stable:
Flutter 1.12.13+hotfix.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 27321ebbad (13 days ago) • 2019-12-10 18:15:01 -0800
Engine • revision 2994f7e1e6
Tools • Dart 2.7.0
Master:
Flutter 1.13.6-pre.16 • channel master • https://github.com/flutter/flutter.git
Framework • revision fcaf9c4070 (2 days ago) • 2019-12-21 14:03:01 -0800
Engine • revision 33813929e3
Tools • Dart 2.8.0 (build 2.8.0-dev.0.0 886615d0f9)
Any ideas how to resolve this?
Hey, I had the same issue this morning but found a fix.
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
environment:
sdk: ">=2.5.2 <3.0.0"
Change dart version in pubspec.yml
environment:
sdk: ">=2.6.0 <3.0.0"
then
flutter pub get
flutter clean
And restart Android Studio
Even after changing the dart version didn't work, then just restart your VS Code or whatever editor you're using. Then check if the error is there. If so, then run flutter clean.
I had also this issues in my project, and I resolved my issues by following this steps:
SDK: ">=2.5.2 <3.0.0"
2.Run flutter clean
3.Restart VSCode