Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save twlz0ne/e3f4286c8ccbb04551b847070a156d73 to your computer and use it in GitHub Desktop.
Save twlz0ne/e3f4286c8ccbb04551b847070a156d73 to your computer and use it in GitHub Desktop.
Run Flutter apps in MacOS with IDE support and hot reloading

This setup is only for MacOS. I don't have a windows/linux machine to test.

Clone FDE repo

cd ~
git clone https://github.com/google/flutter-desktop-embedding

Switch to flutter master

flutter channel master

Pull all latest changes

Because current master is not pointing to latest commit

cd ~/flutter
git pull origin master

Set env variable to enable desktop builds

This enables experimental features. Add it to your .profile or rc file if you don't want to run this for every terminal session.

export ENABLE_FLUTTER_DESKTOP=true

Finish setup

flutter doctor

It shoulds say there is one connected device

Create new project

This doesn't have to be inside FDE folder

flutter create hello_world
cp -R ~/flutter-desktop-embedding/example/macos hello_world/macos

[obsolete] Change FDE path

Note: This step is not required anymore because FDE_ROOT has been eliminated from flutter-desktop-embedding project. Thanks @stuartmorgan for the heads up!

Open hello_world/macos/Runner.xcodeproj/project.pbxproj in a code editor. You can do this from Xcode as well.

Replace this

FDE_ROOT = $PROJECT_DIR/../..;

with this

FDE_ROOT = $HOME/flutter-desktop-embedding;

There will be two instances to replace.

Override platform

Flutter framework code doesn't cover macos/linux/windows platforms yet.

So we have to override platform with an existing one like this:

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

void main() {
  debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;

  runApp(MyApp());
}

Run or build

export ENABLE_FLUTTER_DESKTOP=true

flutter run -d macos

flutter build macos
cd build/macos/Build/Products/Release/

IDE support

export ENABLE_FLUTTER_DESKTOP=true

open -a Android\ Studio

open -a Visual\ Studio\ Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment