Skip to content

[pigeon] Consider generating singletons for @EventChannelApi #177723

Description

@zobo

Use case

Hello, I love how pigeon deals with the complexity of native channels, however, due to my unfamiliarity with the topic I made a mistake of calling the generated method for creating an EventChannel stream, thus breaking platform communication with previous instances. I understand that this might be a problem that some Plugin code must deal with, but this also seems a pretty general problem. So, consider generating code that will ensure only one instance of the EventChannel exists. I am currently using this pattern that I found in a plugin that I use:

https://github.com/llfbandit/app_links/blob/e99efa708dde9886e0982d9b53b7b6b05e807c31/app_links/lib/src/app_links.dart#L52-L86

Here a StreamController is used that encapsulates the EventChannel stream and makes sure only one exists and also closing it when no subscribers are left.

Proposal

I propose that the class that is annotated with @EventChannelApi() is used as the singleton class name and that methods or getters in this class create the needed StreamControllers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.r: solvedIssue is closed as solvedteam-ecosystemOwned by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions