Skip to content

Instantly share code, notes, and snippets.

@Coronon
Last active October 15, 2021 21:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Coronon/d1ad1ade2e29f027076f572fe2525532 to your computer and use it in GitHub Desktop.
Save Coronon/d1ad1ade2e29f027076f572fe2525532 to your computer and use it in GitHub Desktop.
Allows you to write your code on Windows and live preview (hot reload) changes to your IOS device. (Requires Mac)

Develop Flutter App on Windows but preview on IOS

The file sync is based on unison.

Windows:

File sync

  1. Download current release of unison

  2. Extract zip-file and add the .\bin dir to your PATH

  3. Setup SSH between your Windows machine -> Mac (preferably public-key)

  4. Set the {WIN_FOLDER_NAME}, {MACBOOK_SSH} and {MAC_ABSOLUTE_PATH} variables in sync_with_mac.ps1

  5. Run the sync_with_mac.ps1 script

You may get an error when using -repeat watch: try renaming unison-fsmonitor.exe -> unison-fsmonitor-2.51.exe (Or current unison-fsmonitor version -> add -debug all to sync_with_mac.ps1)

Mac:

Requires Homebrew for installing required programs.

File sync

  1. Install unison with brew install unison

  2. Install unison-fsmonitor brew install autozimu/homebrew-formulas/unison-fsmonitor

Execute in root flutter dir (pubspec.yaml dir -> {MAC_ABSOLUTE_PATH})

Run Flutter with pidfile

flutter run --pid-file /tmp/flutter_zune.pid

Hot reload on change in /lib

  1. Install entr brew install entr

  2. Run the following command

while true
do
    find lib/ -name '*.dart' | \
        entr -d -p kill -USR1 $(cat /tmp/flutter_zune.pid)
done
unison {WIN_FOLDER_NAME} ssh://{MACBOOK_SSH}//{MAC_ABSOLUTE_PATH} -repeat watch -ignore="Regex ^(.+/)?[^/]*\.class(/.*)?$" -ignore="Regex ^(.+/)?[^/]*\.log(/.*)?$" -ignore="Regex ^(.+/)?[^/]*\.pyc(/.*)?$" -ignore="Regex ^(.+/)?[^/]*\.swp(/.*)?$" -ignore="Regex ^(.+/)?\.DS_Store(/.*)?$" -ignore="Regex ^(.+/)?\.atom$" -ignore="Regex ^(.+/)?\.buildlog$" -ignore="Regex ^(.+/)?\.history(/.*)?$" -ignore="Regex ^(.+/)?\.svn$" -ignore="Regex ^(.+/)?[^/]*\.iml(/.*)?$" -ignore="Regex ^(.+/)?[^/]*\.ipr(/.*)?$" -ignore="Regex ^(.+/)?[^/]*\.iws(/.*)?$" -ignore="Regex ^(.+/)?\.idea$" -ignore="Regex ^(.+/)?doc/api$" -ignore="Regex ^(.+/)?ios/Flutter/\.last_build_id(/.*)?$" -ignore="Regex ^(.+/)?\.dart_tool$" -ignore="Regex ^(.+/)?\.flutter-plugins(/.*)?$" -ignore="Regex ^(.+/)?\.flutter-plugins-dependencies(/.*)?$" -ignore="Regex ^(.+/)?\.packages(/.*)?$" -ignore="Regex ^(.+/)?\.pub-cache$" -ignore="Regex ^(.+/)?\.pub$" -ignore="Regex ^build$" -ignore="Regex ^lib/generated_plugin_registrant\.dart(/.*)?$" -ignore="Regex ^(.+/)?app\.[^/]*\.symbols(/.*)?$" -ignore="Regex ^(.+/)?app\.[^/]*\.map\.json(/.*)?$" -ignore="Regex ^android/app/debug(/.*)?$" -ignore="Regex ^android/app/profile(/.*)?$" -ignore="Regex ^android/app/release(/.*)?$" -ignore="Regex ^android/(.+/)?gradle-wrapper\.jar(/.*)?$" -ignore="Regex ^android/\.gradle(/.*)?$" -ignore="Regex ^android/captures$" -ignore="Regex ^android/gradlew(/.*)?$" -ignore="Regex ^android/gradlew\.bat(/.*)?$" -ignore="Regex ^android/local\.properties(/.*)?$" -ignore="Regex ^android/(.+/)?GeneratedPluginRegistrant\.java(/.*)?$" -ignore="Regex ^android/(.+/)?key\.properties(/.*)?$" -ignore="Regex ^android/(.+/)?[^/]*\.keystore(/.*)?$" -ignore="Regex ^android/(.+/)?[^/]*\.jks(/.*)?$" -ignore="Regex ^ios/(.+/)?dgph(/.*)?$" -ignore="Regex ^ios/(.+/)?[^/]*\.mode1v3(/.*)?$" -ignore="Regex ^ios/(.+/)?[^/]*\.mode2v3(/.*)?$" -ignore="Regex ^ios/(.+/)?[^/]*\.moved-aside(/.*)?$" -ignore="Regex ^ios/(.+/)?[^/]*\.pbxuser(/.*)?$" -ignore="Regex ^ios/(.+/)?[^/]*\.perspectivev3(/.*)?$" -ignore="Regex ^ios/(.+/)?[^/]*sync$" -ignore="Regex ^ios/(.+/)?\.sconsign\.dblite(/.*)?$" -ignore="Regex ^ios/(.+/)?\.tags[^/]*(/.*)?$" -ignore="Regex ^ios/(.+/)?\.vagrant$" -ignore="Regex ^ios/(.+/)?DerivedData$" -ignore="Regex ^ios/(.+/)?Icon[^/](/.*)?$" -ignore="Regex ^ios/(.+/)?Pods$" -ignore="Regex ^ios/(.+/)?\.symlinks$" -ignore="Regex ^ios/(.+/)?profile(/.*)?$" -ignore="Regex ^ios/(.+/)?xcuserdata(/.*)?$" -ignore="Regex ^ios/(.+/)?\.generated$" -ignore="Regex ^ios/Flutter/App\.framework(/.*)?$" -ignore="Regex ^ios/Flutter/Flutter\.framework(/.*)?$" -ignore="Regex ^ios/Flutter/Flutter\.podspec(/.*)?$" -ignore="Regex ^ios/Flutter/Generated\.xcconfig(/.*)?$" -ignore="Regex ^ios/Flutter/ephemeral$" -ignore="Regex ^ios/Flutter/app\.flx(/.*)?$" -ignore="Regex ^ios/Flutter/app\.zip(/.*)?$" -ignore="Regex ^ios/Flutter/flutter_assets$" -ignore="Regex ^ios/Flutter/flutter_export_environment\.sh(/.*)?$" -ignore="Regex ^ios/(.+/)?ServiceDefinitions\.json(/.*)?$" -ignore="Regex ^ios/Runner/GeneratedPluginRegistrant\.[^/]*(/.*)?$" -ignorenot="Regex ^ios/(.+/)?default\.mode1v3$" -ignorenot="Regex ^ios/(.+/)?default\.mode2v3$" -ignorenot="Regex ^ios/(.+/)?default\.pbxuser$" -ignorenot="Regex ^ios/(.+/)?default\.perspectivev3$"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment