Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pigeon] Better documentation for @FlutterApi usage #108531

Closed
knaeckeKami opened this issue Jul 28, 2022 · 8 comments · Fixed by flutter/packages#3705
Closed

[pigeon] Better documentation for @FlutterApi usage #108531

knaeckeKami opened this issue Jul 28, 2022 · 8 comments · Fixed by flutter/packages#3705
Labels
p: pigeon related to pigeon messaging codegen tool P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. r: fixed Issue is closed as already fixed in a newer version

Comments

@knaeckeKami
Copy link
Contributor

knaeckeKami commented Jul 28, 2022

Use case

The documentation and example of pigeon describe the usage of @HostApi, which is used to call into native code from flutter.
But Pigeon also supports @FlutterApi, which enables the native code to call into Flutter code, typically used for Steam-like updates that are not initiated from the Flutter side, but from the OS/native side.
This feature is not mentioned only briefly in the README and there are no examples that showcase it.

Proposal

Pigeon should have better documentation for@FlutterApi in the README and either add an example project or at least link to a third-party package that uses it.

In a quick search I only found these third-party projects using it:

@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Jul 28, 2022
@danagbemava-nc
Copy link
Member

But Pigeon also supports @FlutterApi, which enables the native code to call into Flutter code, typically used for Steam-like updates that are not initiated from the Flutter side, but from the OS/native side.
This feature is not mentioned in the README and there are no examples that showcase it.

This isn't entirely accurate. See https://pub.dev/packages/pigeon#calling-into-flutter-from-the-host-platform

Nonetheless, more documentation is always good.

@danagbemava-nc danagbemava-nc added p: first party package flutter/packages repository. See also p: labels. p: pigeon related to pigeon messaging codegen tool and removed in triage Presently being triaged by the triage team labels Jul 28, 2022
@knaeckeKami knaeckeKami changed the title [pigeon] Document @FlutterApi usage [pigeon] Better documentation for @FlutterApi usage Jul 28, 2022
@knaeckeKami
Copy link
Contributor Author

Sorry, yeah, I missed that. I updated the issue.

@stuartmorgan stuartmorgan added the P3 Issues that are less important to the Flutter project label Aug 2, 2022
@ghost
Copy link

ghost commented Sep 23, 2022

Yes, that Twilio example is pretty good. On my host (iOS Swift) side I was doing flutterApi = MyPluginFlutterApi(), when I should have been doing:

flutterApi = MyPluginFlutterApi(binaryMessenger: registrar.messenger())

and therefore nothing was getting called on the Flutter side! (Going over the Twilio example pointed that out to me, but a quick README example would have been much faster/easier to find.) The generated Pigeon code allows me to instantiate the FlutterApi without a binary messenger, which was why it wasn't working -- binaryMessenger should really be a required argument. (Maybe not for mocking, but then why not then just require a mocked messenger?)

And had to figure out how to extend the MyPluginFlutterApi on the Dart side as well. But there, it uses the default binary messenger in Flutter -- but it obviously can't do that on the host side and needs to be instantiated with it. In both places, it needs to be "setup", which a quick example would really help with as well:

MyPluginFlutterApi.setup(MyPluginFlutterApiImpl(instance: this));

Pigeon is amazing! Respectfully, I would not regard the small paragraph stating one can use @FlutterApi "...The steps are similar but reversed...." as, "documentation." Please provide brief, simple examples for the @FlutterApi similar to the ones for @HostApi so we know what to do -- and so all your hard work on this framework gets fulfilled when people see how much easier it really is than dealing with channels directly. Would be great (easy?) to even just add a host-to-Flutter method sending a value to the existing examples, with a comment that it is optional or something.

@daniloapr
Copy link
Contributor

Pigeon is really amazing and easy to use, but its poor documentation makes it very tricky. I just created a plugin a found multiple issues that were not touched by the documentation. Even the example repository provided is not up to date, implementing the version 1.0.0 while pigeon is already in 4.2.5.

Note that lots of Flutter devs don't have experience with native code, so more complete examples would be much appreciated.

@Sri-Kumaran-DR
Copy link

checkout this blog for more info on using @FlutterApi()

@learncodingforweb
Copy link

I am also not able to do native to flutter communication on android using java.
Please provide example code, how use @FlutterApi with android java?

@andreisas06
Copy link

@learncodingforweb The webview_flutter plugin uses Pigeon. I was learning myself how to use it and found this a great example to learn from.

auto-submit bot pushed a commit to flutter/packages that referenced this issue Jun 30, 2023
Updates README's to better reflect modern pigeon and it's usage. 
Very open to feedback on this, please let me know what could be better, clearer, or is just missing from this documentation.
I don't expect to be able to cover all uses with this, if people want to see all possibilities, I think looking into our very thorough integration tests will provide them with anything they could need (all of which is linked in the example README).

fixes flutter/flutter#66511
partial work for flutter/flutter#123851
fixes flutter/flutter#108531
fixes flutter/flutter#92641
@danagbemava-nc danagbemava-nc added the r: fixed Issue is closed as already fixed in a newer version label Jul 3, 2023
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: pigeon related to pigeon messaging codegen tool P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants