2
3

More than 1 year has passed since last update.

Flutter自体のバージョンを切り替える方法

Last updated at Posted at 2020-10-12

今はfvmを使用しています。

以下過去の記事

複数のFlutterアプリを開発しているとFlutter自体のバージョンを切り替えることもあります。
今のFlutterではバージョンの切り替えをスムーズにする方法がサポートされていないので、試行錯誤の結果以下の方法でバージョンを切り替えています。

リポジトリのclone

depthやブランチは指定せずにcloneします。

git clone https://github.com/flutter/flutter.git

stableチャンネルを参照する

上の方法でcloneするとmasterブランチ(チャンネル)を参照しているので以下のコマンドでstableに変更します

flutter channel stable

任意のバージョンに変更する

以下のgitコマンドでローカルリポジトリを任意のバージョンに変更します。この例では1.17.4に変更しています。

cd flutterリポジトリ
git checkout 1.17.4

以下のようにdetached HEADになったよと言われますが、 git checkout stable で stableブランチに戻れるので、特に気にしなくてよいです。

Updating files: 100% (3130/3130), done.
Note: switching to '1.17.4'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 1ad9baa8b9 Change iOS device discovery from polling to long-running observation (#59695)

最新にしたい

stableブランチ(チャンネル)に戻れば、clone時点の最新になります。
試していませんが、新しいバージョンがリリースされたときは git pull あたりで stable チャンネルの最新にできそうです。

cd flutterリポジトリ
git checkout stable

最後に

flutter version flutter upgrade/downgrade など使う方法も検索すると見つかりましたが、複数のバージョンを気軽にスイッチするには、この方法が私的にはベストでした。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3