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
startvia FFI - There is a second C function called
stopwhichs 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.
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.
- 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
Startbutton and start a long running isolate - In the console: Press
Shift + r-> Hot restart is not working - In the app: Click the
Stopbutton -> Long running process is stopped - In the console: A message appeared, that hot reload was performed
| 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 |