The original address: naveen. Hashnode. Dev/flutter – ver…

Naveen. Hashnode. dev

Release date: August 29, 2021

In this article, we will learn about version management in Flutter. Here we will see how to set up and version manage flutter. So, let’s get started.

Earlier, we learned what a Flutter version Manager (FVM) is and how to use it. First of all, we need to know, do you really need this or do you not need versioning?

Why do we need version management in Flutter?

While working on a Flutter project, you may need to switch between different SDK versions to validate and test the upcoming release of Flutter with your application, which can be tedious and time consuming. This is where version management comes in.

There are different types of Flutter versions available for our machine. This way, every time, Flutter can test the application against the updated Flutter version, without waiting for installation, and will be able to switch to the Flutter version accordingly.

How are we versioning

There are actually two ways to do this.

  • Naive Approach (via alias)
  • Tool Base (via FVM)

Naive Approach

It doesn’t matter what operating system you’re using, what shell you’re using, aliases, they’re all the same, some of them are here, some of them are technical.

Suppose this is the base directory of your Flutter SDKs. $HOME/dev/flutter_sdks

Here, you download different channels to the Flutter SDK

cd $HOME/dev/flutter_sdks
git clone -b stable https://github.com/flutter/flutter.git flutter_stable
git clone -b beta https://github.com/flutter/flutter.git flutter_beta
git clone -b dev https://github.com/flutter/flutter.git flutter_dev
git clone -b master https://github.com/flutter/flutter.git flutter_master
Copy the code

Now it’s time to review everything in your base directory.

╭ ─ adityaa @ naveenin ~/dev/flutter_sdks 
 ╰─λ ls
flutter_stable
flutter_beta
flutter_dev
flutter_master
Copy the code

Now it’s time to use aliases, open your.bashrc,.zshrc, config.fish, or whatever.

vim ~/.bashrc

# flutter sdks alias
 alias flutter="$HOME/dev/flutter_sdks/flutter_stable"
 alias flutterb="$HOME/dev/flutter_sdks/flutter_beta"
 alias flutterd="$HOME/dev/flutter_sdks/flutter_dev"
 alias flutterm="$HOME/dev/flutter_sdks/flutter_master"
Copy the code

Now you can use the naive version through an alias

Attention! You can clone not only branches, but also versions by tag.

Based on the tool

The Flutter Version Manager is a very important and easiest way to manage multiple Flutter SDK versions and channels without going into the full setup when we need to access some other Flutter SDK versions for our project.

FVM follows the same principles as our alias method, but the only difference is that the FVM global configuration and default directory use symbolic links to specific Flutter versions.

Steps for installing the Flutter version Manager

  • The first step is to check if the Flutter is installed on our system to work on FVM. Run the following command on your terminal –
flutter
Copy the code

If Flutter has been installed on your system, it will show us some common commands used in Flutter.

In addition, if you want to know your version of Flutter, you can run the following command.

flutter --version
Copy the code

This command will return the exact versions of Flutter and Dart installed on our system.

  • Now, in the next step, we must activate FVM on our system, and to do so, we must run the following command
pub global activate fvm
Copy the code

⚠️ If you intend to use the –global flag, do not activate FVM with a flutter pub Global activate. Only pub Global Activate FVM can be used to activate FVM.

Read Dart.dev docs for more information on how to run the global DART script.

  • As we will now see, there are some warnings at the end of the installation process, so we need to add the FVM path to the shell configuration file (.bashrc, bash_profile, etc.) before going any further
export PATH="$PATH:`pwd`/flutter/bin"
export PATH="$PATH:`pwd`/.pub-cache/bin"
Copy the code

The warning will now be removed. To verify that FVM is now fully activated, we will run the $echo PATH command, which will give us the same PATH.

The SDK version is installed.

FVM allows us to install multiple types of Flutter versions or channels.

  • Version — Use stable to install stable channels and use V1.8.0 or 1.17.0-dev.3.1 to install Release.
  • — Skip-setup — Will skip the Flutter Settings after installation
fvm install <version>
Copy the code

Configure the SDK version.

After that, we’ll see if the project is configured to use a particular version. If not, we will install it on the appropriate version, no arguments required.

fvm use
Copy the code

You can use different versions of the Flutter SDK in each project. To do this, you must go to the root directory of the project, and then.

fvm use <version>
Copy the code

If you want to use a particular version on your machine by default, you can specify the flag –global in the use command. A symbolic link to the Flutter version will be created in the fVMHome folder, which you can then add to your PATH environment variable, as shown below. FVM_HOME/default/bin. Use FVM use –help, which will give you the exact path you need to configure.

List of versions of Flutter installed.

We can now list the installed versions on our machine by typing the following command. FVM will store the version of the SDK.

fvm list
Copy the code

Upgrade the SDK version.

Use the upgrade SDK version command when we need to upgrade our current SDK version, so you must call your Flutter SDK command as normal with the flutter installation.

fvm flutter upgrade
Copy the code

Set the IDE.

Now we’ll see how to configure the IDE. Below, we’ve shown how to configure Android Studio and VS Code. Now let’s see.

  • ⇒ Android Studio.

In your root project directory, copy the absolute path of the FVM symlink. For example. /absolute/path-to-your-project/.fvm/flutter_sdk

After that, we will open languages and frameworks in the Android Studio menu → now, search for Flutter and change the path to flutter SDK path. Now you can run and debug the Flutter version of your choice.

  • Flicker VS code.

Now we will configure the VS code, and here we will see how to complete the VS code.

Add the following to your settings.json. This will list all the Flutter SDKS installed while using Flutter when using VSCode. Change the SDK.

Use FVM List to display the paths for each version.

Lists all versions installed by FVM.

{
  "dart.flutterSdkPaths": ["/Users/usr/fvm/versions"]}Copy the code

You can also add version symbolic links for dynamic switching

{
  "dart.flutterSdkPaths": [".fvm/flutter_sdk"]}Copy the code

Use FVM in your project

The goal is to apply a specific version of Flutter to your project by using FVM.

  • Create a FLUTTER project in your development folder by executing flutter create project_name:flutter create.png.

  • Switch to your project directory and execute FVM use

    : FVM use.png

  • If you run FVM List again, you can see the check mark or activity next to the version you used in your project: FVM list.png

If you want to learn more about FVM and configuration, please refer to the official documentation.

If I make a mistake, let me know and correct me in the comments section. I hope you enjoyed this article and found it helpful.


www.deepl.com translation