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:

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

  2. 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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
user@user:~/flutterproject$ flutter run
/mnt/c/Development/flutter/bin/flutter: line 5: $'\r': command not found
/mnt/c/Development/flutter/bin/flutter: line 6: $'\r': command not found
/mnt/c/Development/flutter/bin/flutter: line 14: $'\r': command not found
: invalid optionnt/flutter/bin/flutter: line 15: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
/mnt/c/Development/flutter/bin/flutter: line 16: $'\r': command not found
': not a valid identifierr/bin/flutter: line 17: unset: `CDPATH
/mnt/c/Development/flutter/bin/flutter: line 18: $'\r': command not found
/mnt/c/Development/flutter/bin/flutter: line 19: syntax error near unexpected token `$'{\r''
'mnt/c/Development/flutter/bin/flutter: line 19: `function follow_links() {

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.

  1. Solution: I created couple of commands to help me move to Windows, without having to cd it out. And another to run the compatible flutter command without having to write CMD.exe /c flutter run again and again. Below are the commands and you can use them by pasting them in your .bashrc file and rebooting the terminal.
1
2
3
4
5
alias winpro='cd /mnt/<DIRECTORY IN WINDOWS YOU WANT>'

flutter() {
    command CMD.exe /c flutter $@
}

Now you can run any flutter command in WSL and going to Windows is simple, just type winpro (or whatever you like).