Desktop Deployment

Build Flutter apps for Windows, macOS, and Linux

🖥️ What is Desktop Deployment?

Flutter Desktop allows you to build native applications for Windows, macOS, and Linux from a single codebase. Your app compiles to platform-specific executables with native performance and full access to desktop APIs and features.


# Build for Windows
flutter build windows --release

# Build for macOS
flutter build macos --release

# Build for Linux
flutter build linux --release
                                    

Output:

✓ Built build/windows/runner/Release/

Desktop Platform Features

🪟

Windows

Build native Windows applications with .exe executables. Requires Visual Studio 2022 or later with C++ desktop development workload. Supports Windows 10 and later versions with full Win32 API access.

flutter build windows --release
🍎

macOS

Create native macOS applications with .app bundles. Requires Xcode 13 or later on macOS. Supports macOS 10.14 and later with full Cocoa framework integration and App Store distribution.

flutter build macos --release
🐧

Linux

Build native Linux applications with GTK integration. Requires Linux development libraries (GTK, Clang). Supports major distributions like Ubuntu, Fedora, and Debian with native look and feel.

flutter build linux --release
🔄

Cross-Platform

Share code across all desktop platforms while accessing platform-specific features when needed. Use conditional imports and platform channels for native functionality while maintaining single codebase benefits.

if (Platform.isWindows) { ... }

🔹 Enable Desktop Support

Enable desktop platforms in your Flutter project:

# Check current configuration
flutter config

# Enable Windows
flutter config --enable-windows-desktop

# Enable macOS
flutter config --enable-macos-desktop

# Enable Linux
flutter config --enable-linux-desktop

# Create desktop folders
flutter create --platforms=windows,macos,linux .

# Verify desktop devices
flutter devices

Available Devices:

Windows (desktop) • windows • windows-x64
macOS (desktop) • macos • darwin-x64
Linux (desktop) • linux • linux-x64

🔹 Windows Setup & Build

Requirements and build process for Windows:

Windows Requirements:

  • Windows 10 or later (64-bit)
  • Visual Studio 2022 with "Desktop development with C++"
  • Windows 10 SDK
# Build Windows app
flutter build windows --release

# Output location
# build/windows/runner/Release/

# Run Windows app
flutter run -d windows

# Create installer (using Inno Setup)
# Download Inno Setup from jrsoftware.org

Build Output:

your_app.exe
flutter_windows.dll
data/ (assets folder)

🔹 macOS Setup & Build

Requirements and build process for macOS:

macOS Requirements:

  • macOS 10.14 (Mojave) or later
  • Xcode 13 or later
  • CocoaPods (for dependencies)
# Build macOS app
flutter build macos --release

# Output location
# build/macos/Build/Products/Release/

# Run macOS app
flutter run -d macos

# Open in Xcode
open macos/Runner.xcworkspace

# Create DMG installer
# Use create-dmg or appdmg tools

Build Output:

YourApp.app (application bundle)
Contains all resources and frameworks

🔹 Linux Setup & Build

Requirements and build process for Linux:

Linux Requirements (Ubuntu/Debian):

# Install dependencies
sudo apt-get update
sudo apt-get install clang cmake ninja-build \
  pkg-config libgtk-3-dev liblzma-dev
# Build Linux app
flutter build linux --release

# Output location
# build/linux/x64/release/bundle/

# Run Linux app
flutter run -d linux

# Create AppImage (using appimagetool)
# Or create .deb package (using dpkg-deb)

Build Output:

your_app (executable)
lib/ (shared libraries)
data/ (assets)

🔹 Desktop App Configuration

Configure desktop-specific settings:

Windows Configuration (windows/runner/main.cpp):

// Set window title and size
Win32Window::Size size(1280, 720);
window.CreateAndShow(L"My Flutter App", size);

macOS Configuration (macos/Runner/Configs/AppInfo.xcconfig):

PRODUCT_NAME = My Flutter App
PRODUCT_BUNDLE_IDENTIFIER = com.example.myapp
MARKETING_VERSION = 1.0.0
CURRENT_PROJECT_VERSION = 1

Linux Configuration (linux/my_application.cc):

// Set window properties
gtk_window_set_title(window, "My Flutter App");
gtk_window_set_default_size(window, 1280, 720);

🔹 Create Windows Installer

Package Windows app with Inno Setup:

; installer.iss
[Setup]
AppName=My Flutter App
AppVersion=1.0.0
DefaultDirName={pf}\MyFlutterApp
OutputDir=installer
OutputBaseFilename=MyFlutterApp-Setup

[Files]
Source: "build\windows\runner\Release\*"; DestDir: "{app}"; Flags: recursesubdirs

[Icons]
Name: "{commondesktop}\My Flutter App"; Filename: "{app}\your_app.exe"
Name: "{group}\My Flutter App"; Filename: "{app}\your_app.exe"
# Compile installer
iscc installer.iss

🔹 Create macOS DMG

Package macOS app as DMG installer:

# Install create-dmg
brew install create-dmg

# Create DMG
create-dmg \
  --volname "My Flutter App" \
  --window-pos 200 120 \
  --window-size 800 400 \
  --icon-size 100 \
  --app-drop-link 600 185 \
  "MyFlutterApp.dmg" \
  "build/macos/Build/Products/Release/YourApp.app"

🔹 Create Linux Package

Package Linux app as .deb or AppImage:

# Create .deb package structure
mkdir -p myapp-1.0.0/DEBIAN
mkdir -p myapp-1.0.0/usr/bin
mkdir -p myapp-1.0.0/usr/share/applications

# Copy files
cp -r build/linux/x64/release/bundle/* myapp-1.0.0/usr/bin/

# Create control file
cat > myapp-1.0.0/DEBIAN/control << EOF
Package: myapp
Version: 1.0.0
Architecture: amd64
Maintainer: Your Name
Description: My Flutter App
EOF

# Build .deb
dpkg-deb --build myapp-1.0.0

🔹 Desktop-Specific Code

Handle platform-specific functionality:

import 'dart:io' show Platform;

class DesktopHelper {
  static bool get isDesktop {
    return Platform.isWindows || Platform.isMacOS || Platform.isLinux;
  }
  
  static String get platformName {
    if (Platform.isWindows) return 'Windows';
    if (Platform.isMacOS) return 'macOS';
    if (Platform.isLinux) return 'Linux';
    return 'Unknown';
  }
  
  static void configureWindow() {
    if (Platform.isWindows) {
      // Windows-specific configuration
    } else if (Platform.isMacOS) {
      // macOS-specific configuration
    } else if (Platform.isLinux) {
      // Linux-specific configuration
    }
  }
}

🔹 Common Desktop Issues

Troubleshoot desktop deployment problems:

Issue: Visual Studio Not Found (Windows)

Solution: Install Visual Studio 2022 with C++ desktop development workload

Issue: GTK Libraries Missing (Linux)

Solution: Install required packages: sudo apt-get install libgtk-3-dev

Issue: Code Signing Error (macOS)

Solution: Configure signing in Xcode or disable for development builds

Issue: DLL Not Found (Windows)

Solution: Ensure all DLLs are in the same directory as the .exe file

🧠 Test Your Knowledge

Which command builds a Flutter app for Windows?