DEV Community

Andrew
Andrew

Posted on

Add Desktop Support to an Existing Flutter Project

Your Flutter app runs on Android and iOS, but the repository has no windows/, macos/, or linux/ folder. Nothing is broken: platform host projects are generated when the app is created, and a mobile-only scaffold never receives desktop files. The Flutter CLI can add them in place, without starting a new project or moving your Dart code.

This tutorial shows the exact command, how to add all three desktop targets or just one, what Flutter writes into your project, how to install each toolchain, and what to check when a desktop device never appears in flutter devices.

Table of Contents

Why the Platform Folder Is Missing

Every flutter create run renders a set of platform templates. A command such as flutter create --platforms=android,ios my_app creates only the Android and iOS host projects. Your lib/main.dart remains portable, but there is no Win32 window, Xcode project, or GTK runner for desktop.

The same gap appears when a project was scaffolded before desktop support was enabled in the SDK, or when someone removed unused platform folders from the repository. The fix is not to create a second app and copy files across. flutter create can run against an existing directory: pass the project root as the target (.) and list the platforms you want. Flutter's desktop support documentation gives this retrofit command directly and notes that it adds the necessary desktop files and directories to an existing project.

This walkthrough assumes pubspec.yaml describes an app (project_type: app in .metadata). A Dart package has no runnable host app, and a plugin uses a different platform implementation layout.

Before You Run the Command

Commit or stash your work first. The new platform folders become source files that you will want to review, and a clean diff makes it obvious exactly what the command added.

It also helps to update the SDK before generating hosts:

flutter --version
flutter upgrade
flutter doctor -v
Enter fullscreen mode Exit fullscreen mode

The create command adds missing files, but it does not silently rewrite every existing native file. If a project already has an outdated desktop runner, Flutter's migration guide for pre-3.3 Windows projects shows the pattern: back up with git, delete the specific files that need regenerating, run flutter create --platforms=windows ., and review the result before building.

Add All Three Desktop Targets

From the root of the existing project, run:

cd /path/to/your_app
flutter create --platforms=windows,macos,linux .
Enter fullscreen mode Exit fullscreen mode

The final . means "this directory." Without a target argument, the command has nowhere to write the host projects and exits with a usage error. Keep the platform list comma-separated with no spaces, because spaces split the value into extra command-line arguments.

You should see Flutter recreating the project and writing new host folders. Your Dart sources, dependencies, and assets stay where they are; the command supplies the native shells that let the same Dart entry point start on each desktop platform.

Before and After

A mobile-only project typically looks like this:

my_app/
├── android/
├── ios/
├── lib/
│   └── main.dart
├── test/
├── pubspec.yaml
└── .metadata
Enter fullscreen mode Exit fullscreen mode

After adding all desktop targets, the same project root also contains windows/, macos/, and linux/. If you add web as well, a web/ folder appears too.

Add Only the Targets You Need

You do not have to generate all three desktop hosts. The --platforms value accepts any subset:

flutter create --platforms=linux .
flutter create --platforms=macos .
flutter create --platforms=windows .
flutter create --platforms=windows,linux .
Enter fullscreen mode Exit fullscreen mode

Adding one platform does not delete the folders for the others. To add web to an existing project, Flutter's web guide uses this form:

flutter create . --platforms web
Enter fullscreen mode Exit fullscreen mode

That creates a web/ directory with the bootstrap assets for a browser build. Generating a folder is not the same as being able to build on that target, however: Windows, macOS, and Linux hosts each require their own operating system and native toolchain.

What the Create Command Adds

Each new folder is a small native host project, not a copy of your app:

Folder What it contains
windows/ A CMake project and a C++ Win32 runner that creates the window, starts the Flutter engine, loads plugins, and runs the message loop
macos/ An Xcode project, the Runner.xcworkspace, entitlements files, and app-level build settings
linux/ A CMake project and a GTK-based runner for the Linux desktop shell
web/ index.html, manifest.json, icons, and the bootstrap files used by Flutter web

The Windows runner documentation describes the generated runner app in detail. It also shows the settings worth reviewing in the new host: the window title and initial size in windows/runner/main.cpp, the executable name in BINARY_NAME inside windows/CMakeLists.txt, the icon in windows/runner/resources, and the version and copyright fields in windows/runner/Runner.rc. macOS and Linux hosts have their own bundle or application identifiers and display names; set those before you ship a release.

Flutter also updates .metadata, the file the tool uses to track platform migrations. After the command, its migration list should include the new platforms alongside root, android, and ios:

migration:
  platforms:
    - platform: root
      create_revision: <sdk-revision>
      base_revision: <sdk-revision>
    - platform: windows
      create_revision: <sdk-revision>
      base_revision: <sdk-revision>
    - platform: macos
      create_revision: <sdk-revision>
      base_revision: <sdk-revision>
    - platform: linux
      create_revision: <sdk-revision>
      base_revision: <sdk-revision>
Enter fullscreen mode Exit fullscreen mode

Keep .metadata in version control and do not edit it by hand. Your pubspec.yaml dependencies and Dart entry point are not regenerated by this step.

To compare the retrofitted layout with a project scaffolded for multiple platforms from day one, the full walkthrough of creating a Flutter project shows what the original flutter create command produces, including how --org sets the Android and iOS identifier prefix.

Install the Desktop Toolchain

Generating the folders is enough for Flutter to know the targets exist, but it will only list a device when the host toolchain passes its checks.

Target Required tooling
Windows Visual Studio with the Desktop development with C++ workload
macOS Xcode, its command-line tools, and CocoaPods for plugin native code
Linux clang, cmake, ninja-build, pkg-config, libgtk-3-dev, and libstdc++-12-dev
Web A supported browser such as Chrome or Edge; no desktop toolchain

On Windows, install current Visual Studio rather than Visual Studio Code, and select the C++ desktop workload. Flutter's Windows setup guide calls out that Visual Studio is a separate IDE and is supported only on Windows, then uses flutter doctor -v and flutter devices to validate the result. If Visual Studio is already installed, Microsoft's guide to modifying Visual Studio workloads walks through adding the workload from the installer.

On macOS, Flutter's macOS setup guide covers the full sequence: install Xcode, point the command-line tools at it with xcode-select, run xcodebuild -runFirstLaunch, accept the Xcode license, and install CocoaPods. The macOS target can only be built on a Mac.

On Debian or Ubuntu, Flutter's Linux setup guide gives the package list and install command:

sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev libstdc++-12-dev
Enter fullscreen mode Exit fullscreen mode

After installing anything, run flutter doctor -v again. The desktop documentation notes that you can ignore problems for platforms you do not target, or disable those platforms with flutter config flags such as --no-enable-ios. Restart your IDE after changing platform settings so it can detect the new device.

Run Each Desktop Target

On the matching operating system, from the project root, first confirm the device is visible:

flutter devices
flutter run -d windows
Enter fullscreen mode Exit fullscreen mode

Use flutter run -d macos on a Mac and flutter run -d linux on Linux. If you omit -d, Flutter lists the available targets and asks you to pick one. While the app is running, press r for hot reload and R for hot restart.

When you are ready to produce release binaries, the commands follow the same target names:

flutter build windows
flutter build macos
flutter build linux
Enter fullscreen mode Exit fullscreen mode

Run the Web Target

Web support does not need the C++ or Xcode toolchains. Add the folder, then run against a browser:

flutter create . --platforms web
flutter run -d chrome
Enter fullscreen mode Exit fullscreen mode

On Windows you can use -d edge, and -d web-server serves the app at a local URL for any browser. Flutter's web build guide documents these device options and notes that web hot reload is enabled by default as of Flutter 3.35. For a release build, flutter build web writes the deployable bundle to build/web.

Troubleshooting a Missing Desktop Device

If flutter devices lists only a phone or an emulator, work through these checks in order. Device detection depends on the toolchain, not just on whether the platform folder exists.

  1. Run the command from the project root. Confirm that windows/, macos/, or linux/ sits next to pubspec.yaml. If it is missing, rerun flutter create --platforms=... . from that root, not from inside lib/.
  2. Read flutter doctor -v. Fix every red error under the toolchain section for the target you care about, then rerun it. The Windows, macOS, and Linux setup guides all use this command as the gate before listing devices.
  3. Check the Windows workload. Visual Studio Code alone is not enough. Install Visual Studio with Desktop development with C++, then restart the terminal and IDE so the updated environment is visible.
  4. Check the macOS toolchain. Confirm that xcode-select -p points at the Xcode you installed, that xcodebuild -runFirstLaunch has completed, that the license is accepted, and that CocoaPods is installed for plugins with native macOS code.
  5. Check for a graphical Linux session. All the packages in the table must be present. A headless SSH session, container, or WSL setup without a display server cannot show a Linux desktop window, so run from a desktop terminal instead.
  6. Check whether desktop was disabled in the SDK. Current stable releases enable desktop by default, but an older configuration may not. Re-enable the target with flutter config --enable-windows-desktop, --enable-macos-desktop, or --enable-linux-desktop, then restart the IDE.
  7. Separate build failures from device failures. If the device appears but the build stops on a package, check whether that plugin lists Windows, macOS, or Linux support on pub.dev. A mobile-only plugin can block a desktop build even though the runner is generated correctly.

If you regenerated files but the old runner still fails, compare the folder against a fresh scaffold or follow the migration guide for that platform, and run flutter clean before trying again.

Conclusion

Adding desktop support to an existing Flutter app is a single retrofit command run from the project root:

flutter create --platforms=windows,macos,linux .
Enter fullscreen mode Exit fullscreen mode

The command leaves your Dart code in place and adds native host projects for the platforms you list. Afterward, confirm the new folders and .metadata entries, install the matching toolchain, restart your IDE, and run each target with flutter run -d windows, -d macos, or -d linux. Add web separately with flutter create . --platforms web and run it with -d chrome. When a device does not appear, start with flutter doctor -v and the platform-specific setup checks rather than regenerating the whole project.

Top comments (0)