How to change the current Dart SDK version? - flutter

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

Related

I have updated flutter sdk version to 2.10.0 but in terminal error coming saying : current version is 2.8.0

i have updated the sdk version of flutter to 2.10.0 but still old version (2.8.0) is showing in terminal due to which i am unable to use google fonts in my app as the google fonts require sdk version >=2.10.0. I Have used these two commands to upgrade - flutter upgrade and flutter pub get
Check for version file in flutter SDK. Open the flutter SDK folder and open the version file. It use to have a version specified, also check for the flutter version in VS Code at the bottom bar. If both are 2.10.0, then just flutter clean the project and rebuild. IF 2.8.0 is still there, download 2.10.0 zip file and unzip and replace the flutter SDK path.
You would check your flutter's SDK version through the below command
flutter doctor -v
Once you type above command, the system will show you about the current config

How to change used Dart version in Android Studio?

So I am trying to run this command in terminal
flutter pub run intl_translation:extract_to_arb --output-dir=lib/i18n lib/i18n/app_localization.dart
and I get this error
Dart 2.15.1 is incompatible with your dependencies' SDK constraints. Please run "flutter pub get" again.
pub finished with exit code 65
And I noticed that the used Dart version is 2.15.1 and not version 2.10.5 which is specified in the Android Studio project settings
How would I change the actually used Dart version to be able to run the intl_translation command ?
You can download the version you want from this link. https://dart.dev/get-dart/archive
From SDK manager in android studio you can change the flutter SDK and dart SDK to the path of the versions you want to use.
And then restart IDE

How do I upgrade an existing Flutter app?

I have an existing Flutter app that I built half a year ago. I checked on pubspec.lock, it has this line:
sdks:
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.16.0 <2.0.0"
So I assume the app was built for Flutter v1.16.
How do I upgrade this app to use the latest Flutter's version? Running "flutter doctor" gives me [√] Flutter (Channel stable, 1.22.3, on Microsoft Windows [Version 10.0.19041.630], locale en-US), so my SDK is already updated to the latest version.
Interestingly, when I create a new app from scratch, the pubspec.lock does not have any information about the Flutter's version. The same section now contains only this: sdks: dart: ">=2.10.0-110 <2.11.0". In the future, how would I know which version was this app running?
I have tried running "flutter upgrade" within my app, but that was to upgrade the SDK, not the Flutter version of the app. So how do I upgrade my app to use the latest Flutter version? Or is it always built using the latest version of the SDK? Can't I target my app to build with specific version of Flutter?
To update the project to null safety follow these steps:
Side note: change the flutter version in pubsec.yaml, make new project and copy the following line:
sdk: ">=2.12.0 <3.0.0"
Then follow the steps:
Run flutter upgrade in the terminal to upgrade Flutter
Run dart migrate to run the dart migration tool.
Solve all errors which the migration tool shows.
Run flutter pub outdated --mode=null-safety to print all outdated packages.
Run flutter pub upgrade --null-safety to upgrade all packages automatically.
Check the code for errors and solve them (Very important).
Run dart migrate again and it should now be successful. Follow the link to checkout the proposed changes.
Press the "Apply Migration" button.
Check the code for errors again and fix them.
Your project should be updated now.
Referenced from this website.
Go ro the root directory of your flutter project and run flutter upgrade. This will upgrade both your existing flutter project and flutter SDK to latest version.
Run the command:
flutter upgrade
Additional for upgrading to latest stable version only
If you want to upgrade to latest version only then please first check your current flutter channel
Step 1:
Check for Stable channel
flutter channel
You will get output like this:
beta
dev
master
* stable
If output was not like this then please proceed to Step 2 or directly proceed to Step 3
Step 2:
Switch to flutter stable channel
flutter channel stable
Now you will get output like this:
beta
dev
master
* stable
Step 3:
Run the below command to upgrade to latest stable version of flutter
flutter upgrade
Inside your project root, run below command
flutter upgrade
This command will update the Flutter SDK locally installed on your workstation, wondering how does that make sense?
After you run, above command flutter upgrade the SDK is updated locally and whenever you build or run your flutter app now, it should always pick up the latest stable version (stable channel) installed locally.
to check run,
flutter channel
you should get something like below based on what version is installed locally on your workstation.
Flutter is already up to date on channel stable
Flutter 2.0.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 4d7946a68d (3 days ago) • 2021-03-18 17:24:33 -0700
Engine • revision 3459eb2436
Tools • Dart 2.12.2
You can always switch to a different channel with below command,
flutter channel dev
flutter upgrade
Answer to - the Flutter SDK locally installed on your workstation, wondering how does that make sense?
Open your pubspec.yml file and see below:
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
Where version: 1.0.0+1 is your flutter app version
When you run command flutter run your app should pick up the environment as defined which is sdk: ">=2.1.0 <3.0.0"
With all dependencies as defined under,
dependencies:
flutter:
sdk: flutter
where sdk: flutter states that the SDK should be pulled from your locally installed SDK version.
Recall, how you had installed the Flutter SDK first time, on your local workstation, as below MAC example, See all SDK releases
cd ~/development
unzip ~/Downloads/flutter_macos_2.0.3-stable.zip
later, Update your path, and run flutter doctor.
OR
git clone https://github.com/flutter/flutter.git -b stable
later, Update your path, and run flutter doctor.
Note: You may check your pubspec.lock file that may look like below,
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
flutter: ">=1.16.0" <---- Use SDK greater than this installed locally
I will show you an easy way to migrate old code projects.
My recommendation is not to work on the existing old project. Instead, create a new project where you can turn your existing project code into new clean, tidy code at a time.
Now put a line of code on the existing old code project terminal as below.
$ flutter create -t <project-type> <new-project-path>
For example, your terminal code like,
PS C:\Users\habib\VScodeProject\git_ripository\simple-weather-old> flutter create -t app C:\Users\habib\VScodeProject\git_ripository\simple-weather-new
Done.
After that, Your new project will no more show any system problems, like gradle problem, android manifesto problem i.e.
If you want to see more about flutter migrating: [See this flutter doc]
if you upgrade your project, but still have problem. then please check your path spellin is ok or not!?
I also face this problem. after upgrading project it won't work for me. then i look to my code, there was miss path.

How to downgrade your flutter SDK version?

My current Dart SDK Version is 2.1.2-dev.0.0.flutter-0a7dcf17eb.
However i need to use a flutter text recognition Dependency that requires SDK version >=1.23.0 <2.0.0
How can I downgrade my version?
In the Flutter install directory execute
git checkout v1.2.2
Now run
flutter doctor
You can just go from a version to another using the new commands
flutter downgrade -> go to the previous
flutter upgrade -> update to the new one
If you have a specific version of Flutter that you want to switch to (e.g. a previous stable version), you can use the flutter version command:
First find the version you wish to switch to here: https://flutter.dev/docs/development/tools/sdk/releases
Then, use flutter version command:
flutter version v1.9.1+hotfix.3
To pin Flutter package to a specific version, specify Flutter version explicitly in the pubspec.yaml file environment section:
environment:
sdk: '>=1.19.0 <3.0.0'
flutter: ^0.1.2
You have to run one command
flutter version
Above command shows you list of flutter version after that you can choose any version from that list. Using for example flutter version v1.9.1+hotfix.6

How to run flutter projects with different/older Dart SDK dependencies?

The current Dart SDK version is 2.1.0-dev.9.4.flutter-f9ebf21297.
Because NewsBuzz requires SDK version >=1.8.0 <2.0.0, version solving failed.
I am trying to run projects from https://startflutter.com. There are several older projects using older versions of Dart SDK or with dependencies requiring older Dart SDK version.
Is there any way to run multiple versions of Dart without downloading the older version of Dart and changing the environment variables manually?
I have gone through several StackOverflow posts and lot of Github issues without finding a proper solution.
Flutter lower dart version
Where is Dart's SDK located within /flutter folder?
Specifying SDK version in the pubspec.yaml does not seem to help.
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
Edit: Dart & Flutter support for Visual Studio Code docs says something about dart.sdkPaths and dart.flutterSdkPaths settings.
I had a similar problem:
My pubspec.yaml had the following:
environment:
sdk: ">=2.1.0 <3.0.0"
However when running flutter packages get I got the following error:
Running "flutter packages get" in xxx-app-mobile...
The current Dart SDK version is 2.1.0-dev.9.4.flutter-f9ebf21297.
Because xxx_app requires SDK version >=2.1.0 <3.0.0, version solving failed.
pub get failed (1)
I tried using the exact version name as the environment variable it did not work. I tried:
flutter upgrade
flutter clean
flutter update-packages
Received the same error when running flutter packages get
I then downgraded the version requirements in the pubspec.yaml to:
environment:
sdk: ">=2.0.0 <3.0.0"
And flutter packages get worked...
So I had an app that was developed on flutter 1.x SDK's, but after my completion, I moved on to build other projects and eventually shifted to fllutter2.0
As of now, flutter downgrade only lets you go one version back, Also going back from 2.x to 1.x seems difficult
So I went to this https://docs.flutter.dev/development/tools/sdk/releases site and downloaded the version i made the app in.
Then I had my dart-sdk for that specific project changed in Android Studio
Then I did the following
Deleted .idea folder and build folder as well as pubspec-lock file.
run flutter pub get
finally flutter build apk
Now this was a dire situation so I had to resort to this
I really will not recommend this unless you are in a rough spot
Simply update you flutter sdk to latest version.
First open your command (cmd) as an adminstrator then upgrade flutter : flutter upgrade it will do everything for you