Putting the Flutter desktop app together

  • Tutorial


Today I will show you how to run your existing Flutter desktop application (MacOS, Linux or Windows).

First, you’ll have to switch the Flutter channel from release to master. To do this, you need to run the following commands on the command line:

flutter channel master
flutter upgrade

Then you need to set the environment variable ENABLE_FLUTTER_DESKTOP to true .

To do this, do the following on the command line:

Mac OS and Linux


Windows PowerShell


Windows CMD


After that, you should see your desktop in the list of available devices to run Flutter. To verify this, run the flutter devices command


As you can see in the screenshot, Mac OS appeared in my list of available devices.

Next, we need to look into the following repository:

We are interested in the contents of the example directory , namely the macos , linux and windows folders . These are runners for the respective platforms - native applications within which Flutter works. Exactly the same as you can see in the directory of your project when you create a project using the flutter create command .

Just copy the runner for the platform you are interested in to the project directory. This step is necessary because flutter create does not yet support the automatic creation of runners for the desktop.

Already almost done. Now you need to edit your main.dart a little

Add the following imports:

import 'dart:io' show Platform;
import 'package:flutter/foundation.dart' 
show debugDefaultTargetPlatformOverride;

Change main () as follows:

void main() {
  debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;

Last step. Run the following commands:

flutter packages get
flutter precache --linux

Done! Now just run flutter run and your application will build on the desktop!

Important Note:

It should be borne in mind that many third-party plugins that you used in your Flutter applications will not work on the desktop, as they depend on native APIs. In the future, the situation, of course, will change, but so far it is better not to use this method for something serious.

Also popular now: