2024.03.15
FlutterのSDKバージョンをディレクトリ毎に設定する
同一の開発端末(Mac,Windowsなど)で、Flutter案件を複数同時に開発する場合、プロジェクトの開発毎に、flutterのSDKバージョンを切り替えるのは面倒なので、フォルダ毎にflutterのSDKバージョンを切り替えられると便利です。
その際、バージョン管理ツール「asdf」を利用すると切り替えができ開発がスムーズに進みます。
以下、asdfの導入手順を説明していきます。
1.asdfをインストールします。
brew install asdf
2.Pathを通します。環境変数へ反映。
echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ~/.bash_profile
source ~/.bash_profile
3.asdfに用意されているflutterプラグインをインストールする
asdf plugin add flutter
4.特定のFlutterバージョンをインストールする前に、インストール可能なバージョンを確認します。
asdf list all flutter

5.Flutterのバージョン3.19.3-stableと3.16.8-stableをインストールします。
asdf install flutter 3.19.3-stable
asdf install flutter 3.16.8-stable
添付画像のようなエラーが出て「jq」インストールするようエラーメッセージが出る場合は、brew install jqでインストールを行なってください。

6.インストール済みのflutterバージョンを確認します。
asdf list flutter

7.Flutterプロジェクト毎にバージョンを指定できます。
cd projectA
asdf local flutter 3.19.3-stable
flutter --version
3.19.3-stable
cd projectB
asdf local flutter 3.16.8-stable
flutter --version
3.16.8-stable
