Should I worry about Flutter and Dart version being different? - flutter

Flutter uses the dart-lang SDK (and executable). So when I want to see what version I'm using, I run this and get the following:
Flutter
flutter --version
Output
Flutter 1.23.0-18.1.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 198df796aa (7 days ago) • 2020-10-15 12:04:33 -0700
Engine • revision 1d12d82d9c
Tools • Dart 2.11.0 (build 2.11.0-213.1.beta)
Version: 2.11.0
Dart
But when I check my machine's dart version. I see something different..
dart --version
Output
Dart SDK version: 2.10.2 (stable) (Tue Oct 13 15:50:27 2020 +0200) on "macos_x64"
Version: 2.10.2
How can I make sure I'm always using the same dart-sdk and executable between the dart tool and flutter? What is managing the two tools? Should I worry about Flutter and Dart version being different (edit)?

You shouldn't worry, but more importantly, the 2 versions are built for each other.
For example, when you install an old version of Flutter, the version of Dart which will be used will not be the latest version of Dart, but the one that was released around the same time as the Flutter you are using.
I learnt this in my question/ GitHub issue, Choose specific Dart version used by Flutter
.
Flutter is tightly coupled to Dart, so you can't mix and match versions. If you really wanted to run a specific version of Dart that it wasn't built with you would need to fork the framework and the engine and custom-build your own combination, which would almost certainly include lots of changes to make them compatible. Stuart Morgan, Flutter team

Flutter version and dart version don't have to be the same. You can see from here, the latest Dart SDK version is 2.10.0. But there are lots of newer versions in Flutter as in here. Dart has a version note in their documentation:
As of Flutter 1.21, the Flutter SDK includes the full Dart SDK. This site’s documentation and examples use version 2.10.0 of the Dart SDK.

If you have installed the dart sdk separately before, you could just delete it, and then the dart sdk included in the Flutter will be used automatically.
find the installation folder which dart
if it is not in the flutter SDK folder
then just rm -r the folder

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.

How to change the current Dart SDK version?

I ran the following commands in my foo project:
iDecode#iDecodes-Mac foo % pub get
Resolving dependencies...
The current Dart SDK version is 2.7.2.
Because foo requires SDK version >=2.12.0 <3.0.0, version solving failed.
iDecode#iDecodes-Mac foo % flutter --version
Flutter 2.6.0-11.0.pre • channel dev
Tools • Dart 2.15.0 (build 2.15.0-116.0.dev)
My pubspec.yaml file has:
environment:
sdk: '>=2.12.0 <3.0.0'
As you can see my current Dart SDK version is set to 2.7.2, my project is targeting a min of 2.12.0 and Dart SDK installed on my machine is 2.15.0. So, how do I change the current Dart SDK version?
This is my ~/.zshrc file
export PATH=/flutter/bin:$PATH
export PATH=$PATH:/$HOME/Library/Android/sdk/platform-tools/
export PATH="$PATH:/$HOME/flutter/bin"
export PATH="$PATH":"$HOME/.pub-cache/bin"
export JAVA_HOME=$(/usr/libexec/java_home)
It seems like you installed Flutter/Dart SDK somewhere using Homebrew. Use which flutter and which dart to see the actual Flutter/Dart command that is taking effect. Once you find where your Dart SDK is you can use
brew uninstall dart
After this when you run which dart it will now point to where your Flutter SDK was installed.
You can also try this way:
Just download that specific flutter version from here. and just set the flutter version in your editor and try to run it will run that specific flutter version but make sure you can't run that with terminal commands. So you need to handle all commands from the Tools option.
set flutter version
Must Run commands from here
The dart version is related with flutter version, see which version is what you need here
https://docs.flutter.dev/development/tools/sdk/releases
Upgrade by running flutter upgrade [check it out here] (update dart sdk for flutter)
Flutter comes with dart by default. Suggestion is to delete old flutter, delete .zshrc and download the latest stable version 2.5.3 for your mac and then give path for it in your .zshrc. Other method is switch to flutter stable by running flutter channel stable and then give flutter upgrade command so it will catch all the stuff from git in you local machine and you'll be good to go.
Simply go to the location where Dart SDK is kept and delete that and install a new Dart SDK version from the official website which is
https://dart.dev/get-dart
I had that same issue
Resolving dependencies... (5.3s)
The current Dart SDK version is 2.17.0.
Because talk_to_me depends on browser >=0.3.1+1 which requires SDK version
<2.0.0, version solving failed
I think we need to uninstall dart and install the correct version
To uninstall dart:
sudo apt purge dart

is it possible to continue using flutter SDK "1.20.0" and not upgrading anymore? any future problems can arise from that behavior?

every time i get a notification to upgrade to newer flutter SDK and i do the upgrade...my project gets broken...due to incompatibility of packages with each others...i tried to install the packages again one by one...also tried to manipulate the packages version...i tried to migrate to different flutter channels like master, dev, beta..going back to stable...but no luck :(
and i end up in downgrading the flutter SDK to "1.20.0" again...i did that everytime till the newest version of flutter SDK "1.22.4 1aafb3a 13/11/2020"
once i downgrade to "1.20.0"..everything goes fine...
for example...one of the errors am facing right now using the flutter SDK "1.22.4"..when i flutter pub get..i get this:
Because every version of flutter_common_exports depends on flutter_localizations any from sdk which depends on collection 1.15.0-nullsafety.3, every version of flutter_common_exports requires collection 1.15.0-nullsafety.3.
And because dartx >=0.2.0 <0.5.0 depends on collection >=1.14.11 <1.15.0, flutter_common_exports is incompatible with dartx >=0.2.0 <0.5.0.
So, because myApp depends on flutter_common_exports any which depends on dartx ^0.4.1, version solving failed.
pub get failed (1; So, because myApp depends on flutter_common_exports any which depends on dartx ^0.4.1, version solving failed.)
exit code 1
am using:
Flutter 1.22.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 1aafb3a8b9 (28 hours ago) • 2020-11-13 09:59:28 -0800
Engine • revision 2c956a31c0
Tools • Dart 2.10.4
so what will happen if i didn't follow any upgrade notifications and continue developing my app using flutter SDK "1.20.0" till i release my app to the store ?!
is there any consequences that will happen?!
thanks in advance
In short, you can’t use the latest SDK on this project yet, not while the packages you’re using don’t get updated and are compatible with the latest SDK.
You can use the old SDK, you're just missing out on new features.
If you work with a team, you should start declaring the compatible SDK on your “pubspec.yaml” file, so that everyone knows which SDK version it was tested for:
version: 1.0.0+1
environment:
sdk: ">=2.2.2 <3.0.0"
flutter: "1.9.1+hotfix.6"