Most developers prefer to use Linux or MacOS for development and the major reason in simple terms is the terminal and the ease they provide with their development environments. Windows has always been avoided by most developers (as far as I see in the community) but recently, after the announcement of Windows terminal and the increasing popularity of Windows Subsytem for Linux, many people have taken a stab at developing with Windows without having to install a Linux distro or use a Virtual Machine or in extreme cases, buy Macbooks.
Recently, Flutter has been gaining extreme popularity and everyone is ditching native development to see what Flutter has to offer. I personally like flutter because how easy, fast and beautiful it is. It helps design UIs easily for the algorithms/backend I am working on.
Coming to the main topic, it is pretty easy to setup flutter for any platform be it Windows, Linux or MacOS. But what I wasn’t able to find anywhere was how to use flutter with WSL. Anyone can switch to powershell/cmd for using flutter though, but I like things at one place and below are the steps for the workaound:
Install Flutter in Windows: This is pretty straight forward and one can do this easily by following this link, you’ll also want to install Android Studio for the SDK in Windows itself. Finally, just make sure flutter works in powershell/cmd.
WSL: I assume that you have WSL already setup, if not, you can follow this.
But now, if you’ll try to use Flutter in WSL bash, you will see an error like below.
the work around to this is, intead of running
flutter run, use
CMD.exe /c flutter run, but this too has a limitation that you can only run app repositories stored in Windows, not in WSL server, which is still a problem.
- Solution: I created couple of commands to help me move to Windows, without having to
cdit out. And another to run the compatible flutter command without having to write
CMD.exe /c flutter runagain and again. Below are the commands and you can use them by pasting them in your
.bashrcfile and rebooting the terminal.
Now you can run any flutter command in WSL and going to Windows is simple, just type
winpro (or whatever you like).