Repository navigation
Description
Can a headless FlutterEngine work in iOS App Extensions? I'm trying to share Dart code between my main app and an iOS network extension via a Flutter module by loosely following Adding iOS app extensions and Integrate a Flutter module into iOS
When initializing the FlutterEngine and trying to invoke a MethodChannel in my Extension Service:
let engine = FlutterEngine(name: "extension", project: nil, allowHeadlessExecution: true)
engine.run(withEntrypoint: "main")*
// Create MethodChannel
I get this error:
Modifying properties of a view's layer off the main thread is not allowed: view <UIView: 0x104a57b80> with no associated or ancestor view controller;*
Is this architecture possible? The error suggests Flutter is still trying to create UI components despite running headless.
Addition Details
I have a large amount of Dart code that needs to be reused in my Push Provider Extension. A lot of it is pure Dart, so I can potentially at least reuse that using ffi(I think). But a good chunk uses Flutter as well (local notifications, audio, local storage). It would be awesome to reuse all of it in the iOS extension. I was hoping that running the FlutterEngine without the UI would create a smaller footprint and still allow access to the Flutter SDK. I really can't find any direct documentation around this.
Activity
darshankawar commentedon Mar 26, 2025
@AlexNik4
Check if this maybe is related / similar to your case or not.
AlexNik4 commentedon Mar 27, 2025
@darshankawar Thanks for your response! Since the approach isn’t outright impossible, I tested further in a minimal sample project using a Packet Tunnel Network Extension (to avoid App Push Provider entitlement requirements). I ended up avoiding any additional plugins for now.
Current Setup in the Extension Service
Confirmed the entrypoint is correct (misnamed withEntrypoint or libraryURI throw Dart_LookupLibrary errors).
headless.dart Entrypoint:
Issues Observed
The Dart handler is never triggered.
I’d greatly appreciate any guidance—thanks again for your time!
darshankawar commentedon Mar 28, 2025
Thanks for the update. I think from Android side, something like workmanager would probably work, but I am not sure if there's equivalent for iOS, so I'll keep the issue open for team's tracking.
hellohuanlin commentedon Apr 18, 2025
From reading
FlutterEngine.mm, there are quite a few places that could have been skipped for headless mode. For example, text input plugin setup (which involves creating a fewUIViews) isn't necessary for headless mode.dyaboykyl commentedon Nov 14, 2025
Hello, just chiming in that this would be really great to see fixed. We would like to run some business logic in flutter from an extension and that logic is not UI-related.
Gibbo97 commentedon Jan 29, 2026
We have been trying to run the flutter engine in a Notification Service Extension. Although I believe the changes needed are the same.
Have made a PR #181645
iOS: Ensure engine is run on the main thread (flutter#191626)
iOS,macOS: Check viewType before creating a platform view (flutter#19…