You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Export a base class for Objective C method channel plugins #9161
Maybe it would be easier for ObjC plugins to use a FlutterMethodCallHandler protocol rather than a typedefd callback?
A Swift sub-class should look... swifty. Might be enough to add some _Nullable and _Nonnull annotations.
Consistency with corresponding Android and Dart APIs. For instance, the Android side uses interfaces, not abstract base classes.
We'd like to allow plugin consumers to simply declare a dependency on a plugin in their pubspec.yaml file without any need to touch ObjC/Swift or Android code at all. That requires plugin initialization to be done consistently across the board, making it amenable to code generation during flutter build.
The delegate could be a property of FlutterMethodChannel, I guess, as an alternative to having the FlutterPlugin base class at all. That would mean we have at least three options:
A channel concept using callback blocks (current solution; this issue indicates that is not good enough for many situations, typically because plugins need to maintain state across method calls and/or implement protocols).
A method call handler delegate protocol to be implemented by plugins, and a corresponding delegate property on FlutterMethodChannel.
I have way too little experience with ObjC to know what developers would expect or prefer. Same goes for Swift by the way. @chinmaygarde, do you have an opinion?
/cc @gavindoughtie as an affluent iOS developer for his thoughts. Gavin, the discussion is about the best plugin API on the ObjC (and Swift when we add that) side of things.
Oh, I wish I were an affluent iOS developer... :-P
I'd definitely lean towards defining a couple of delegate protocols (one for the plugin, one for whatever Flutter hands the plugin) as the actual binding contract.
Then I'd do a BasePlugin that implements the protocol, and then most plugins would just extend that by overriding a couple of methods (like "createViewController" or "handleMethod").
This way you keep the requirements minimal while still making it easy for more trivial plugins.
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.
Activity
tvolkert commentedon Apr 3, 2017
Actually, it's better to have the method be:
And the base class implementation can just respond with a method not found error.
mravn-google commentedon Apr 4, 2017
Things to consider:
FlutterMethodCallHandlerprotocol rather than atypedefd callback?_Nullableand_Nonnullannotations.pubspec.yamlfile without any need to touch ObjC/Swift or Android code at all. That requires plugin initialization to be done consistently across the board, making it amenable to code generation duringflutter build.tvolkert commentedon Apr 5, 2017
Yeah, maybe introducing a
FlutterMethodCallHandlerDelegateprotocol and having the interface be something the following would make sense:mravn-google commentedon Apr 5, 2017
The delegate could be a property of
FlutterMethodChannel, I guess, as an alternative to having theFlutterPluginbase class at all. That would mean we have at least three options:delegateproperty onFlutterMethodChannel.I have way too little experience with ObjC to know what developers would expect or prefer. Same goes for Swift by the way. @chinmaygarde, do you have an opinion?
tvolkert commentedon Apr 5, 2017
/cc @gavindoughtie as an affluent iOS developer for his thoughts. Gavin, the discussion is about the best plugin API on the ObjC (and Swift when we add that) side of things.
gavindoughtie commentedon Apr 5, 2017
Oh, I wish I were an affluent iOS developer... :-P
I'd definitely lean towards defining a couple of delegate protocols (one for the plugin, one for whatever Flutter hands the plugin) as the actual binding contract.
Then I'd do a BasePlugin that implements the protocol, and then most plugins would just extend that by overriding a couple of methods (like "createViewController" or "handleMethod").
This way you keep the requirements minimal while still making it easy for more trivial plugins.
tvolkert commentedon Apr 5, 2017
+1 to a base class that implements one or more protocols.
mravn-google commentedon May 9, 2017
Fixed by #3645.
tvolkert commentedon May 9, 2017
flutter-team-archive/engine#3645 rather?
mravn-google commentedon May 9, 2017
Yes, thanks.
github-actions commentedon Sep 5, 2021
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.