Skip to content

Support env variables in project configurations #562

Closed

Description

@smallTrogdor

Today there is no way to set environment variables for the flutter run command per project configuration. The process started by FlutterRun inherits Neovim's environment, so env vars have to be exported in the shell before starting Neovim, or set with vim.env in pre_run_callback. The vim.env approach leaks the value into the whole Neovim session and is not undone when switching to another configuration.

Other editors support this per run configuration (IntelliJ "Environment variables", VS Code launch.json "env").

Proposal: add an optional env field to setup_project configurations:

require("flutter-tools").setup_project({
  {
    name = "Dev",
    flavor = "dev",
    env = { API_KEY = "abc", LOG_LEVEL = "debug" },
  },
})

The values would be merged on top of Neovim's environment and only applied to the run/debug process of that configuration: the job runner (plenary Job env) and the debugger runner (launch config env). Other jobs like pub get or devices stay unchanged, which keeps the scope small (see #89).

Happy to open a PR if this sounds good.

Activity

  1. sidlatau commented on Oct 30, 2026

    @sidlatau
    Collaborator

    Thanks for the detailed proposal and the offer to send a PR! I went ahead and implemented it in #565 following your design: env on a project configuration is merged on top of Neovim's environment for the job runner, and passed as the launch configuration's env for the debugger runner. Other jobs like pub get and devices are unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions