Skip to content

Instantly share code, notes, and snippets.

@ajinasokan
Last active November 22, 2019 14:38
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ajinasokan/4a0340c07f36200d487fb2b22b4996db to your computer and use it in GitHub Desktop.
Save ajinasokan/4a0340c07f36200d487fb2b22b4996db 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
@waf
Copy link

waf commented Nov 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment