Skip to content

gatzsche/flutter-dart-ffi-hotreload-issue

Repository files navigation

Hot Reload Issues with Long Running Isolates

Summary

This sample projects demonstrates an issue (flutter/flutter#59061) with hot reload and dart FFI.

  • The project creates an isoloate
  • The isolate calls a long running C function start via FFI
  • There is a second C function called stop whichs stops the first function
  • The long running isolate breaks hot reloading and hot restart

We need a callback informing the application about an upcoming hot reload. The callback then can call the stop function to stop the long running isolate Once stopped hot reloading will work as expected.

Existing Solutions

There is already a reassemble method on State class which can be overridden. But this method informs only after a reload has been performed, note before.

Example App

  • On Mac: Start Xcode Simulator App
  • Open a terminal
  • Type flutter pub get
  • Type cd example
  • Type flutter run
  • In the console: Press Shift + r -> Hot restart will work
  • In the app: Click the Start button and start a long running isolate
  • In the console: Press Shift + r -> Hot restart is not working
  • In the app: Click the Stop button -> Long running process is stopped
  • In the console: A message appeared, that hot reload was performed

Code Files

File Description
ios/Classes/StartStop.cpp The long running native code
lib/flutter_dart_ffi_hotreload_issue.dart Code for starting an isolate with a long running process
example/lib/main.dart The user interface

Related Sources

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published