How to specify local Flutter version (e.g. an older release)? - flutter

I would like to test my application / package running on an older version of Flutter, e.g. specifically Flutter v2.2.3.
There are 2 commands, flutter upgrade and flutter downgrade which might seem to be relevant, but how do I select the specific version of Flutter I want to use? flutter upgrade --help and flutter downgrade --help do not provide any extra information.

Recommended (git): Just checking out a specific commit in the Flutter repo
Change directory to your flutter installation folder, e.g. /opt/flutter.
git checkout the git tag (change to the branch pointed by the tag). For example, there is a git tag called 2.5.0 for the version 2.5.0, so run git checkout 2.5.0. (Thanks Eugene :) )
Or alternatively, if I want version 2.5.0, I can get the commit SHA (ref) from the Flutter SDK releases page. That website says the ref for 2.5.0 is 4cc385b. At the flutter installation directory, run git checkout 4cc385b.
Then in the terminal, run flutter (or any specific flutter command) to download and build this version of flutter.
Using FVM (Flutter version Management)
You also specify the specific version of Flutter using FVM, e.g. fvm use 2.5.1
Download the specific version of Flutter from Flutter SDK releases and install it.
This is the slowest way, as you would have to download the entire repo again.

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

Related

How to update specific flutter SDK channel?

Currently, i m using flutter 3.3.9 i want to update it to 3.7.3
Any particuler command?
Note : I don't want to affect my current code
Need perment solution for it.
Change channel if you are not in correct channel otherwise go to step 4
Open a terminal or command prompt on your computer.
Check the available Flutter channels by running the command flutter channel.
This will show you the list of available channels and the current channel you are on.
Switch to the desired channel by running the command flutter channel <channel-name>.
For example, to switch to the stable channel, you can run flutter channel stable.
Choose the version.
This is possible now with flutter version. In the console do flutter version to list the versions available. Then choose a version to switch to: flutter version v3.7.3
For these cases, try to use FVM (Flutter Version Management).
fvm install 3.7.3
fvm use 3.7.3
For get more detail here its official website https://fvm.app/
The advantages is you can any cases you can simply go back to your previous flutter version. And also you can work different flutter project with different version

How to downgrade flutter from version 2.5.3 to 1.22.6

I have some older projects built on flutter 1.22.6 and now I am working on latest version of flutter but there often comes need when I've to work on previous projects non null safety one's so when I try to downgrade flutter by giving command flutter downgrade 1.22.6 it tells me to downgrade to 2.5.2 and if I try to switch channel and then downgrade it downgrades to 2.5.2 first and then tells there is no version related to 1.22.6. This method used to be working before but now its not working anymore. I don't want to download zip files and then replace again flutter every-time I just want it to be done by cli.
My OS is windows 11
You can use flutter Version Manager fvm its specifically made to control flutter versions plus along with that you can install flutter sidekick as well. I am attaching link for you.
FVM Flutter Sidekick
Since you can no longer downgrade flutter versions, I have found the best way to do this is:
Download desired flutter version
Locate current 'flutter' folder and replace it with the desired version
if you run --flutter version after, it should show the correct version

Flutter version used in project

Where can I see the flutter version used in a flutter project? Is there a file inside the project directory where I can see it? I think it is not specified inside the pubscpec.yaml file
So far, I think the specific version can not be found but only what versions can be used in a project. It can be found at the bottom part of pubscpec.lock file
pubspec.lock screenshot
It will not show version project wise. It will overall flutter version that you have installed in your system. For that:
Open your flutter project root directory in Command Prompt or Terminal type:
flutter --version command.
After typing the above command hit enter and You’ll see it will display us the currently installed flutter and Dart version in your computer and also tells us which version type we have installed like Stable or Beta.
Note: There is no such feature/command to check about which version of flutter you have used in Specific project.
Check this thread it will give you more idea:
https://github.com/flutter/flutter/issues/14230
All projects you run will use the flutter sdk installed in your machine/computer from where you specified its location from. So if the version the project uses don't match with the version you've and they conflict, you will have errors and if there is a huge gap and breaking changes, you'll need to either upgrade or downgrade the sdk. But most of the time, things are deprecated before they just become breaking changes and so you shouldn't have big issues. So the best thing to do is usually to upgrade. First check your sdk version via flutter --version. If its outdated, use flutter upgrade to upgrade it.
You can either run flutter --version to check flutter version installed on your machine or check it in your pubspec.lock file for current flutter version in your project
sdks:
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.16.0 <2.0.0"

How to use the flutter downgrade command to switch to an older version of Flutter SDK?

I got the following error when trying to switch to an older version (1.17.4) from my current version (Flutter 1.20.1 • channel stable).
> flutter downgrade
There is no previously recorded version for channel "stable".
Channel "beta" was previously on: 1.17.0-dev.3.1
flutter downgrade is the recommended way for switching versions instead of the deprecated flutter version command. However, there's no documentation I may refer to how it is used.
Another approach to downgrading is to change to the flutter-sdk directory and using git you can checkout a particular tag.
List the available tags with:
git tag
Then switch to a particular one with (e.g.):
git checkout 1.24.0-10.2.pre
(as I had to do today).
Note that this will switch which channel you are on and lock you at that version until you switch back with something like flutter channel dev once you believe the issue you faced is resolved.
in my case , I switched flutter channel master then flutter downgrade v1.22.6 it work
or by using git
git checkout 1.24.0-10.2.pre(any version name)
flutter downgrade only works if you have a previous version of flutter installed from the same channel. It seems like you don't, so please use flutter version v1.17.4.
Find a list of flutter versions here: https://flutter.dev/docs/development/tools/sdk/releases
Check your flutter channel:
flutter channel
Show like this:
Flutter channels:
master
dev
beta
* stable
Change to master:
flutter channel master
Run command:
flutter downgrade v1.22.6
if you want to keep both versions just download a zip of old version and put in the same folder where is a new version and change its name or you can change flutter path

How to use both Flutter stable and dev SDK on the same machine?

I'm working with Flutter to make a Mobile App using the stable Flutter SDK release. But I also want to try Flutter Desktop and Flutter Web that are not part of the Flutter stable channel yet, but are present on the Flutter dev channel.
My question is... How can I try Flutter Desktop and Flutter Web without override the Flutter stable release on my machine?
You'll need to setup alias to switch between different environments easily.
See here a detailed article for that.
I found this Dart package called Flutter Version Management that does exactly what I want.
As the docs says:
Flutter Version Management: A simple cli to manage Flutter SDK versions.
Features:
Configure and use Flutter SDK version per project
Ability to install and cache multiple Flutter SDK Versions
Fast switch between Flutter channels & versions
Dynamic SDK paths for IDE debugging support.
Version FVM config with a project for consistency across teams and CI environments.
Set global Flutter version across projects
https://github.com/leoafarias/fvm
Now I just need to add FVM_HOME/default/bin to the PATH and FVM will take care of everything...
Two solutions
Put the installation files in two different directories one with stable and the other dev and add one of them to the path then you can change the path variable when needed to use the other channel.
Put the flutter repository file in two different directories one with stable and the other with dev then,
add the first installation to the path then add an alias to point to the second installation directory.