Skip to content

Commit

Permalink
feat: add option to configure flutter mode via config (#314)
Browse files Browse the repository at this point in the history
It will add possibility to run app in `profile`, `release` modes.
  • Loading branch information
sidlatau authored Dec 19, 2023
1 parent 6cbe2cd commit 69466cc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ require('flutter-tools').setup_project({
name = 'Web',
device = 'chrome',
flavor = 'WebApp'
},
{
name = 'Profile',
flutter_mode = 'profile', -- possible values: `debug`, `profile` or `release`, defaults to `debug`
}
})
```
Expand Down
8 changes: 8 additions & 0 deletions lua/flutter-tools/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ local function get_run_args(opts, conf)
local target = conf and conf.target
local dart_defines = conf and conf.dart_define
local dart_define_from_file = conf and conf.dart_define_from_file
local flutter_mode = conf and conf.flutter_mode
local dev_url = dev_tools.get_url()

if not use_debugger_runner() then vim.list_extend(args, { "run" }) end
Expand All @@ -148,6 +149,13 @@ local function get_run_args(opts, conf)
vim.list_extend(args, { "--dart-define", ("%s=%s"):format(key, value) })
end
end
if flutter_mode then
if flutter_mode == "profile" then
vim.list_extend(args, { "--profile" })
elseif flutter_mode == "release" then
vim.list_extend(args, { "--release" })
end -- else default to debug
end
if dev_url then vim.list_extend(args, { "--devtools-server-address", dev_url }) end
return args
end
Expand Down
1 change: 1 addition & 0 deletions lua/flutter-tools/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local ui = lazy.require("flutter-tools.ui") ---@module "flutter-tools.ui"
---@field target string
---@field dart_define {[string]: string}
---@field dart_define_from_file string
---@field flutter_mode string

local M = {}

Expand Down
20 changes: 20 additions & 0 deletions tests/commands_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,24 @@ describe("commands", function()
["KEY=VALUE"] = 1,
})
end)

it(
"should add '--profile' config option correctly",
function()
assert.are.same(
{ "run", "--profile" },
commands.__get_run_args({}, { flutter_mode = "profile" })
)
end
)

it(
"should add '--release' config option correctly",
function()
assert.are.same(
{ "run", "--release" },
commands.__get_run_args({}, { flutter_mode = "release" })
)
end
)
end)

0 comments on commit 69466cc

Please sign in to comment.