Skip to content

feat(apple): let the host app supply the FlutterDartProject for background engines - #745

Open
zkrige wants to merge 1 commit into
fluttercommunity:mainfrom
zkrige:feat/apple-shared-dart-project
Open

zkrige wants to merge 1 commit into
fluttercommunity:mainfrom
zkrige:feat/apple-shared-dart-project

Conversation

@zkrige

@zkrige zkrige commented Oct 21, 2026 •

Copy link
Copy Markdown

Summary

BackgroundWorker creates the headless FlutterEngine with project: nil (BackgroundWorker.swift:159-163 on main). Flutter then builds a new FlutterDartProject for it, so its settings can differ from the main engine's. Flutter's own spawnWithEntrypoint shares the project instead (FlutterEngine.mm:1575-1577).

I hit this with Shorebird code push. A new project re-resolves the newest downloaded patch. If a patch downloads while the app runs, the background engine loads a snapshot that does not match the running VM and the process aborts in Dart_CreateIsolateGroup.

This adds WorkmanagerPlugin.setDartProject(_:). The host app creates one FlutterDartProject at launch, shares it with its engine and passes it here, and BackgroundWorker hands it to the engine.

Opt-in: if setDartProject is never called, dartProject stays nil and the engine is created exactly as before.

The README/docs change is a short note in docs/quickstart.mdx. I did not edit the CHANGELOG, since melos generates it from the PR title.

Tested

  • flutter build ios --debug --no-codesign in example: built Runner.app
  • flutter test in workmanager_apple: all 28 tests pass
  • No unit test added: BackgroundWorker needs a Flutter engine, so per AGENTS.md it is not unit-testable.

@docs-page

docs-page Bot commented Oct 21, 2026

Copy link
Copy Markdown

To preview the documentation for this pull request, visit the following URL:

docs.page/fluttercommunity/flutter_workmanager~745

Documentation is deployed and generated using docs.page

…round engines

BackgroundWorker created its headless FlutterEngine with project: nil, so every
task built a fresh FlutterDartProject whose settings can differ from the main
engine's. Add WorkmanagerPlugin.setDartProject(_:) so the host app can share
one project with the background engines. Behavior is unchanged when it is not
called.
@zkrige
zkrige force-pushed the feat/apple-shared-dart-project branch from ec31a4e to a68d284 Compare October 21, 2026 04:28

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant