Develop Linux Apps with Flutter on Windows Machine

Aachman Garg
Flutter Community
Published in
6 min readSep 19, 2020

Flutter gives us the power to develop and maintain cross platform applications from a single code base. While it’s still a work in progress, the platform support is improving rapidly. With the recent announcement of partnership between Flutter and Canonical teams, it’s easier than ever to develop and deploy Flutter apps on Linux.

I couldn’t wait to test it out, but all I had was a Windows laptop. Sure I had options of dual booting, virtualization, etc. but none of them provided a seamless development experience. Not to mention the hassle of setting all this up.

Last week, the latest release of Kali Linux introduced many features, including kali-win-kex, which provides a seemingly native desktop experience on WSL 2. The next thing that came to my mind was, “Let’s run Flutter on this thing!”.

It truly is!

Windows Subsystem for Linux

WSL is a compatibility layer for Windows 10 that allows us to run Linux based command line tools. Microsoft takes it a step further by building WSL 2 on top of a real Linux kernel, which translates to significant improvement in performance and functionality.

WSL 2 provides enough speed and stability required for a good development experience. So, let’s go ahead and set it up.

Step 1: Install WSL

Launch Powershell as administrator and run this:

Step 2: Reboot!

Step 3: Enable WSL and Virtual Machine Platform

Launch Powershell as administrator and run these two commands:

Step 4: Reboot again!

Step 5: Install Linux Kernel

Download and install the WSL 2 Linux Kernel from here: https://aka.ms/wsl2kernel

Step 6: Set default version to WSL 2

Launch Powershell as administrator and run:

Now that WSL 2 is installed, we’re ready to install Kali Linux Distro.

Kali Linux

Go to Microsoft Store and download a copy of Kali Linux.

Yes, it’s that simple ;)

We can simply launch Kali like any other app. On first launch, it’ll take some time to set things up and ask you to create a username and password.

Win-Kex

Windows Kali Experience or win-kex provides Kali GUI with XFCE Desktop connected to Windows through Virtual Network Computing (VNC) connection. Everything is local, so it boots up instantly and lag is negligible.

Install win-kex by performing this command:

This command will install many components including XFCE DE, TigerVNC server and viewer. It’ll take some time, so wait patiently :)

After it’s done, we can launch the GUI with this little command:

This small command starts a VNC server on the Linux side, viewer on the Windows side and connects them all in one go. Sweet!

Here’s how it looks!

I already have a folder for Flutter projects ;)

A couple of things

  • Make sure you’re not in Windows directory while launching $ kex command.
  • run $ kex stop after every session.

Keep these two things in mind to avoid unnecessary errors and keep things smooth.

Let’s Flutter?

Canonical has made it super simple to install Flutter on Linux using snapd. But WSL doesn’t support snapd officially, and workaround isn’t quite simple. So, we’ll just go with the manual way and download Flutter from here.

After download, simply extract it wherever you like :)

Flutter docs suggest to update the path to use Flutter across terminal sessions. But there’s a small problem here, we are not solely running Linux. We have it running on top of Windows, and it has access to the Windows file system.

This means, if we have Flutter installed on Windows, whenever we run a flutter command, it looks at the Windows side of things and ignores the Linux installation of Flutter, even if we update the path. I know, it's weird and super annoying (had to learn this the hard way 😢).

So here’s the workaround! We can run flutter doctor by accessing it like this:

Works like a charm! But, It’s way too long! That’s not how it’s supposed to be, right?

To fix this, we’ll use the alias feature of Bash. Simply run this command to create the flutter alias:

This will work perfectly for the current terminal session.

Now, to make it persist across terminal sessions, we have to edit the .bashrc file.

In the file, add the following line at the exact location:

Press ctrl + x to exit the editor, and press y and enter to save the changes.

Now, just type this command to make the alias available in current session.

Okay, a lot of steps there, but we are done! Now flutter command works just as we expect :)

Developing Linux

We need to set some things up to develop desktop apps on Linux.

Change Flutter channel to dev:

Enable development for Linux desktop:

All we need now are some utilities for Linux development. You can run flutter doctor to check what all you need. Everything can be installed in a single command:

Wait for the install and run flutter doctor again, to check for the last time.

Here we have it! Flutter, fully configured to develop Linux apps on Windows 10.

Now we can just go ahead and write Flutter apps on the distro itself. Or, we can use the VS Code Remote WSL extension to code on Windows and run on Linux. It’s a way smoother experience.

VS Code

Install the extension.

Go to the desired directory and type:

Now, VS Code will open in that directory in the Linux file system. Even the integrated terminal will default to Bash.

You also need to install Flutter and Dart extensions for WSL.

Done!

Everything will work as you expect. Just that flutter run will only build apps when called from Linux GUI (kex). When called from integrated terminal, it won't be able to locate the display and app will not run.

So, let’s see what the development experience looks like!

Well, that’s all!

I hope you loved this guide/hack that tries to simplify cross platform development and improve developer efficiency. While Flutter is aiming to become the universal SDK, Windows is actively trying to become the ultimate platform for developers. And looking at the current progress, this doesn’t seem to be very distant.

Check out my previous work!

Any questions or suggestions? Put them all in the comments section :D

Liked the article? Press and hold on the 👏 button! That’ll motivate me to write more and more!

You can find me on LinkedIn, stalk my GitHub, follow me on Twitter or email me at imaachman@gmail.com for any kind of tech discussion.

--

--