LoginSignup
1
3

More than 1 year has passed since last update.

Flutter Flavor使用時のブレークポイントの有効化

Posted at

内容

Flavorを追加したら、VSCodeでデバッグ(ブレークポイント)できなくなってしまったので、設定の方法を残します。

前提条件

すでにFlavorを追加していること。

開発環境

PC : macOS Big Sur
エディター : Visual Studio Code

Flutter 2.5.1

コマンド

Flavorを追加したときは以下のようなコマンドを入力して、実行するようになります。

flutter run --flavor staging

flutter run --flavor production

※run --flavor hogehoge のhogehoge部分はそれぞれのプロジェクトによる

コマンドから実行すると、ブレークポイントが使用できない。

対応内容

launch.jsonを生成して、以下のような設定にする。

launch.json
{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "my-app production",
      "request": "launch",
      "type": "dart",
      "program": "lib/main.dart",
      "args": [
        "--flavor",
        "production",
      ]
    },
    {
      "name": "my-app staging",
      "request": "launch",
      "type": "dart",
      "program": "lib/main.dart",
      "flutterMode": "debug",
      "args": [
        "--flavor",
        "staging",
      ]
    },
  ]
}

launch.jsonのargsには コマンドで入力していた、 run の後ろの引数を入力する。

flutterModeをdebugにすると、ブレークポイントが有効になる。

この状態で、F5でデバッグ実行が行えて、ブレークポイントも有効になる。

launch.jsonの生成方法は参考の2つ目の記事を参照してください。

参考

1
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
1
3