Skip to content

[Windows] Allow plugins to post platform thread tasks using PluginRegistrarWindows #190089

Closed

Description

@Gustl22

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

Activity

  1. changed the title [-][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`[/+] on Jul 27, 2026
  2. changed the title [-][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`[/+] on Jul 27, 2026
  3. added
    platform-windowsBuilding on or for Windows specifically
    c: proposalA detailed proposal for a change to Flutter
    a: pluginsSupport for writing, building, and running plugin packages
    team-windowsOwned by the Windows platform team
    on Jul 28, 2026
  4. mbcorona commented on Jul 28, 2026

    @mbcorona
    Member

    Hi @Gustl22 , thanks for the report, routing to the windows team for evaluation.

  5. changed the title [-][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`[/+] on Jul 28, 2026
  6. loic-sharma commented on Jul 28, 2026

    @loic-sharma
    Member

    Thanks for opening this issue!

    Add the possibility to access ... engine from PluginRegistrarWindows.

    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 FlutterEngine is not available in the plugins' static library; changing this would require migrating all existing Flutter Windows apps:

    list(APPEND CPP_WRAPPER_SOURCES_CORE
    "core_implementations.cc"
    "standard_codec.cc"
    )
    list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
    list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
    "plugin_registrar.cc"
    )
    list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
    list(APPEND CPP_WRAPPER_SOURCES_APP
    "flutter_engine.cc"
    "flutter_view_controller.cc"
    )

    My recommendation would be to add PostPlatformThreadTask / IsPlatformThread directly to PluginRegistrarWindows.

    Please feel free to send a pull request if you'd like! :)

  7. Gustl22 commented on Jul 29, 2026

    @Gustl22
    ContributorAuthor

    Thank you for the proposal!

    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 FlutterEngine is not available in the plugins' static library; changing this would require migrating all existing Flutter Windows apps

    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 FlutterDesktopPluginRegistrarRef HandleForEngine(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:

    RegisterPlugins(flutter_controller_->engine());

  8. loic-sharma commented on Jul 29, 2026

    @loic-sharma
    Member

    @Gustl22 To make FlutterEngine available to plugins, we'd need to modify windows/flutter/CMakeLists.txt to move "flutter_engine.cc" from CPP_WRAPPER_SOURCES_APP to CPP_WRAPPER_SOURCES_CORE. The problem is that this windows/flutter/CMakeLists.txt file is copied into the user's project when they ran flutter create. If we update this file, users that created their project before our change will still have the old copy of windows/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.

  9. added
    P3Issues that are less important to the Flutter project
    triaged-windowsTriaged by the Windows platform team
    on Aug 12, 2026
  10. Gustl22 commented on Aug 14, 2026

    @Gustl22
    ContributorAuthor

    I see, thank you for the detailed info. Also I confused FlutterEngine with FlutterWindowsEngine. FlutterEngine actually never is exposed in flutter_windows.cc, only FlutterWindowsEngine. I try to make a PR for the discussed methods.

  11. added a commit that references this issue on Oct 22, 2026
    e194458
  12. added a commit that references this issue on Oct 29, 2026
    4773050
  13. github-actions commented on Nov 5, 2026

    @github-actions

    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 -v and a minimal reproduction of the issue.

  14. locked as resolved and limited conversation to collaborators on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: desktopRunning on desktopa: pluginsSupport for writing, building, and running plugin packagesc: proposalA detailed proposal for a change to Flutterplatform-windowsBuilding on or for Windows specificallyteam-windowsOwned by the Windows platform teamtriaged-windowsTriaged by the Windows platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions