Now that we have an overview of the ios project, let’s develop a Flutter plugin that calls the native API for Android and ios. The Flutter plugin communicates with the native web site mainly through channels, with the underlying site transmitting data through binary. Similar cross-platform Hbrid and JSBridge for JS languages such as RN and native communication.
Let’s now create a plug-in that has captured the phone’s battery for example.
Let’s look at the project structure of the plug-in project
Let’s take a look at the Android implementation
The pod must be loaded on ios
A problem discovered during this process is that when SWIFT calls oc methods, the method names are partially omitted.
And it turns out that a lot of oc method names are in the form of the first argument name,The registrar with Registrar with method is listed as the first parameter and the Swift method is in order to increase the readability of the method.
#### both ends of the flutter plugin are implemented. Let’s run the result
Ok, so the plugin is written, and of course it can be shared on GitHub. But just like Android can publish aar, all widgets for Flutter can be published on pub.
We first run the command, flutter packages pub publish –dry-run
< p style = “word-break: block;” style = “word-break: block; Upload to Github and clean the project. Delete the build project. Continue to run the detection commandWe can delete the author column in YAML to execute the final commandflutter packages pub publish
或 sudo flutter packages pub publish -v
flutter packages pub publish --server=https://pub.dartlang.org
Failed to access ping Accounts. Google actually I can access the Internet, the web page can be opened, so I pingedYou can see that Google is not accessible from the command line. The command line agent needs to be set up.
Those who qualify can qualify onto university. @harrychen ➜ flutter_plugin_battery git:(master) qualify export http_proxy=http://127.0.0.1:9999
Those who qualify can qualify onto university. @harrychen ➜ flutter_plugin_battery git:(master) qualify export https_proxy=http://127.0.0.1:9999 @harrychen ➜ Those who qualify can go onto university. Those who qualify can qualify can go onto university. Those who qualify can qualify can go onto university Git: (master) ✗ set http_proxy = http://127.0.0.1:9999
Special attention, each agent’s port is different, do not copy directly, must see your own agent port, this 9999 is my own agent port !!!! You also need to annotate the domestic image. Upload yourself and then let go
Finally, you can find it on the pub