Repository navigation
Closed
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: desktopRunning on desktopRunning on desktopa: pluginsSupport for writing, building, and running plugin packagesSupport for writing, building, and running plugin packagesc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterplatform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallyteam-windowsOwned by the Windows platform teamOwned by the Windows platform teamtriaged-windowsTriaged by the Windows platform teamTriaged by the Windows platform team
Description
Use case
The PR #187365 states to fix the issue #79213. But I still don't know how I can use the functions PostPlatformThreadTask and IsPlatformThread in a windows plugin implementation.
The thing is, in order to use PostPlatformThreadTask, the engine needs to be exposed. But there is no straight way to get the engine from the PluginRegistrarWindows (and this might be on purpose), e.g. see the camera plugin example.
There is an example project, which creates a FlutterViewController themeselves, and therefore can access the engine. But usually plugins don't create their own controller / view to be functional:
| flutter_controller_ = std::make_unique<flutter::FlutterViewController>( |
Proposal
- Document on https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading how to use
PostPlatformThreadTaskandIsPlatformThreadin a regular Windows plugin (without creating a controller first). - Make an example similar to how to use
charging_channel.SetStreamHandler( PostPlatformThreadTaskandIsPlatformThreadon e.g. the event channel, but via thePluginRegistrarWindows. Edit: Or better in here: https://github.com/flutter/demos/blob/33dbc25b9cf637a7b222df682ef21d9bd18041c1/federated_plugin/federated_plugin_windows/windows/federated_plugin_windows_plugin.cpp - If not yet possible: Add the possibility to access
PostPlatformThreadTask/IsPlatformThreadorenginefromPluginRegistrarWindows.
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: desktopRunning on desktopRunning on desktopa: pluginsSupport for writing, building, and running plugin packagesSupport for writing, building, and running plugin packagesc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterplatform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallyteam-windowsOwned by the Windows platform teamOwned by the Windows platform teamtriaged-windowsTriaged by the Windows platform teamTriaged by the Windows platform team
Activity
[-][Windows] Document how Windows engine `PostPlatformThreadTask` and `IsPlatformThread` can be used or expose the engine to `PluginRegistrarWindows`[/-][+][Windows] Document how Windows engine's `PostPlatformThreadTask` and `IsPlatformThread` can be used or expose the engine to `PluginRegistrarWindows`[/+][-][Windows] Document how Windows engine's `PostPlatformThreadTask` and `IsPlatformThread` can be used or expose the engine to `PluginRegistrarWindows`[/-][+][Windows] Document how Windows engine's `PostPlatformThreadTask` and `IsPlatformThread` can be used or expose the engine or methods to `PluginRegistrarWindows`[/+]mbcorona commentedon Jul 28, 2026
Hi @Gustl22 , thanks for the report, routing to the windows team for evaluation.
[-][Windows] Document how Windows engine's `PostPlatformThreadTask` and `IsPlatformThread` can be used or expose the engine or methods to `PluginRegistrarWindows`[/-][+][Windows] Allow plugins to post platform thread tasks using `PluginRegistrarWindows`[/+]loic-sharma commentedon Jul 28, 2026
Thanks for opening this issue!
Unfortunately, this is harder than you'd expect. Flutter Windows creates separate static libraries for the Windows app and Windows plugins. I'm not sure why, but the
FlutterEngineis not available in the plugins' static library; changing this would require migrating all existing Flutter Windows apps:flutter/examples/api/windows/flutter/CMakeLists.txt
Lines 43 to 55 in 6bfd8f4
My recommendation would be to add
PostPlatformThreadTask/IsPlatformThreaddirectly toPluginRegistrarWindows.Please feel free to send a pull request if you'd like! :)
Gustl22 commentedon Jul 29, 2026
Thank you for the proposal!
Not sure I understand correctly. Why would it require migrating existing flutter apps? Can't we just add a method
PluginRegistrarWindows::getEngine()which returns FlutterDesktopEngineRef of FlutterDesktopPluginRegistrarRefHandleForEngine(registrar->engine)without being static? See e.g.:https://github.com/flutter/flutter/blob/c8e3959799890ba195c8fcd377bb6b73f56af021/engine/src/flutter/shell/platform/windows/flutter_windows.cc#L363C1-L368
This would break nothing, but enables all plugin authors to use the functionality of windows
FlutterEngine(which is already public). Did I miss something?Besides that, I am not against just adding the methods, I just wonder why we do not just expose the engine funtionality, while on other places its already exposed in a similar way, see flutter_controller:
flutter/examples/platform_channel/windows/runner/flutter_window.cpp
Line 58 in 0ed149e
loic-sharma commentedon Jul 29, 2026
@Gustl22 To make
FlutterEngineavailable to plugins, we'd need to modifywindows/flutter/CMakeLists.txtto move"flutter_engine.cc"fromCPP_WRAPPER_SOURCES_APPtoCPP_WRAPPER_SOURCES_CORE. The problem is that thiswindows/flutter/CMakeLists.txtfile is copied into the user's project when they ranflutter create. If we update this file, users that created their project before our change will still have the old copy ofwindows/flutter/CMakeLists.txt. Solving this requires asking users to migrate their project, which is painful to do.So instead I'd recommend just adding the methods directly to the
PluginRegistrarWindows. That's just much easier to do.Gustl22 commentedon Aug 14, 2026
I see, thank you for the detailed info. Also I confused
FlutterEnginewithFlutterWindowsEngine.FlutterEngineactually never is exposed influtter_windows.cc, only FlutterWindowsEngine. I try to make a PR for the discussed methods.feat: Expose PostPlatformThreadTask and IsPlatformThread to PluginReg…
feat: Expose PostPlatformThreadTask and IsPlatformThread to PluginReg…
github-actions commentedon Nov 5, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.