The Flutter framework evolves rapidly, introducing new features and breaking changes that often require code updates to stay current. This can divert your focus from feature development to fixing deprecated APIs. Simply keeping your local environment on an “older” version of Flutter doesn’t fully solve the issue. Many developers work on multiple projects, each using different versions of Flutter, which increases the complexity of switching between versions locally.

Another challenge arises when working in a team where each member might have a different local environment. When a new developer joins the team, how do you ensure they use the correct version of Flutter?

The solution is to pin the Flutter version for each project. In this article, I’ll show you how to do this without relying on third-party libraries, providing a scalable solution that works well for larger teams.

Let’s get started.


In my example, I’ll walk you through all the steps, starting from project creation. If you already have a project, feel free to skip ahead to Step 3.

Step 1: Create your project

flutter create flutter_pinned

Step 2: Initialize Git and make your first commit

To keep a clean commit history, initialize Git and commit your initial project:

cd flutter_pinned
git init
git add .
git commit -am "Flutter create project"

Step 3: Add the Flutter submodule

git submodule add -b stable https://github.com/flutter/flutter.git .flutter

Let me explain what happens above. 
The command creates .flutter Git submodule pointing on the Flutter stable branch.

Step 4: Run the project using the pinned version

Run the project from the console using the pinned Flutter version:

.flutter/bin/flutter run

Step 5: Set up pinned Flutter in VSCode

To work with the pinned Flutter version in VSCode, add the following line to your project’s .vscode/settings.json:

{
    "dart.flutterSdkPath": ".flutter",
}

You can create the file manually or let VSCode generate it by opening “Workspace Settings (JSON).”

Open Workspace Settings(JSON)

VSCode Workspace Settings JSON

Run your project from VSCode.

Your project is now pinned to the stable version of Flutter. If you need a different version, such as beta, you can switch channels with:

.flutter/bin/flutter channel beta

Step 6: Share the pinned Flutter version with your team

If you’re working in a team, make sure to commit and push the changes:

git add .
git commit -am "Pin Flutter version"
git push

From now on, everyone in your team should run the following commands to get updates about the code and the Flutter framework version in the submodule.

git pull
git submodule update --init

Thanks for reading!

There is also a video tutorial with all the steps.

Useful links:

  1. Git Submodules
  2. Github Project Example
  3. FutureWare Youtube Channel


Discover more from FutureWare

Subscribe to get the latest posts sent to your email.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

Discover more from FutureWare

Subscribe now to keep reading and get access to the full archive.

Continue reading