flutter-tools.nvim
flutter-tools.nvim copied to clipboard
[Bug]: Windows related issue starting flutter
Describe the bug The same configuration is not working in windows that worked in Linux. I'm attaching a video for reference. Video
To Reproduce Steps to reproduce the behavior:
- Go to any flutter project using Powershell or Git Bash, Open it in NeoVim
- do run the command "FlutterRun" or "FlutterDevices"
- See error
Error is somewhat like this
Error executing Lua callback: ...\site\pack\packer\start\plenary.nvim/lua/plenary/job.lua:405: Failed to spawn process:
stack traceback:
...\site\pack\packer\start\plenary.nvim/lua/plenary/job.lua:405: in function '_execute'
...\site\pack\packer\start\plenary.nvim/lua/plenary/job.lua:448: in function 'start'
...r\start\flutter-tools.nvim/lua/flutter-tools/devices.lua:198: in function 'callback'
...tart\flutter-tools.nvim/lua/flutter-tools/executable.lua:157: in function 'get'
...tart\flutter-tools.nvim/lua/flutter-tools/executable.lua:156: in function 'flutter'
...r\start\flutter-tools.nvim/lua/flutter-tools/devices.lua:190: in function 'list_devices'
...ck\packer\start\flutter-tools.nvim/lua/flutter-tools.lua:31: in function <...ck\packer\start\flutter-tools.nvim/lua/flutter-tools.lua:30>
Expected behavior The expected behavior (that it does in Linux) is to run flutter or show a list of devices.
Screenshots

System information
- OS: Windows 11
- Flutter version: 3.3.3 Channel Stable
- Is flutter in $PATH: Yes it is in C:\Development\flutter\bin\flutter.bat
- neovim version: 0.8.0
Additional context I'm using the default configuration in both my machine Linux and Windows. It works smoothly in Linux but not in Windows.
@Tsuzat I don't use Windows, so there's no chance I'll be able to fix this for you, as I don't know anything about changing the paths or whatever else is required. If you are able to point in the direction of what might not be working, that might be useful. Otherwise, as a Windows user you will have to do some more debugging
@Tsuzat it's important to clarify that you might need to change your config to work with windows and vice versa I've never guaranteed that this would work automatically as I do not use or test on Windows, so I definitely cannot guarantee that. Other Windows users are able to use this plugin successfully, so I doubt this is an issue with the plugin and more likely you need to tweak your configuration using some conditional logic when running on Windows.
I appreciate the hard work you putting in. I don't want to put an extra burden on you. I'll try to debug it by myself. But can you give me an idea of what could have gone wrong with the configuration?
@Tsuzat I'm not really sure what is going wrong but it seems like it's trying to run the command to list the users devices and it cannot find flutter. You seem to have indicated that your flutter path is \\C:Development etc. I would try and run that command i.e. the full path that is in your error message plus the command devices and see if that actually works in your system
I guess I'll use this tool in Linux then. Thanks for the help.
@Tsuzat I dont know, if you're still interested in developing flutter on Windows, but I just had the same error as you. Turns out, that explicitly setting the flutter_path to <path_to_flutter_installation>\bin\flutter.bat seems to solve the issue. There is also an executable in that bin folder called <path_to_flutter_installation>\bin\flutter. This is the one used by the plugin, when not setting the flutter path at all. So @akinsho, it might be good for the windows community to change this to use the .bat instead of the actual executable. I'll see if I can find the exact lines of code to adapt in plugin and report back :)
Turns out, the fn.exepath("flutter") call returns <path_to_flutter_installation>\bin\flutter, which is not the same as Powershell's Get-Command flutter (which returns the bat). So it rather is an error on Vim's side. The same error occurs in dap, as it is also using the vim.fn.exepath() function.
EDIT: exepath seems to be a problematic function for windows altogether, looking at all the issues on vim's and NeoVim's githubs...
I would like to add this solution that I got on Reddit. https://www.reddit.com/r/neovim/comments/xt234i/comment/j1hkdwa/?utm_source=share&utm_medium=web2x&context=3
So, turns out that the plugin uses the flutter binary rather than flutter.bat. The solution is to provide the exact location of the flutter.bat in the setup.
e.g.
local status_ok, flutter_tools = pcall(require, "flutter-tools")
if not status_ok then
return
end
flutter_tools.setup {
flutter_path = "C:/Development/flutter/bin/flutter.bat",
}
Now it is working fine.
Yes, that is the thing I was proposing in my first comment ;) Anyways, this issue should be fixed as soon as https://github.com/neovim/neovim/pull/21175 gets merged. Then, the workaround should not be necessary anymore.