(translated from French : ) Flutter, API natives et plugins (3/3) It was also around May that the , a magnificent mechanism to easily use native features from Flutter/Dart, appeared. Flutter plugin system In the we’ve seen the first part basics of **MethodChannels** In the we saw how to second part create a speech recognition dedicated channel We’ll now see how to modularize this code by . building a dedicated Flutter plugin for iOS and Android The Flutter plugin system 😍 Flutter plugins are managed as simple packages (dependencies), via the Dart package manager. pub Just 1) declare the dependency, 2) run , and Flutter will update the XCode and Android project. It is so effective and transparent, that for the moment I have not even had to understand what Graddle is, nor how a podfile works. Everything is managed by Flutter 😎🍹! pub packages get Even though the is still a little bit embryonic, It already offers some useful, if not necessary, . Flutter plugin catalog tools Use a plugin To use a plugin: declare dependency in the pubspec.yaml of the project dependencies: speech_recognition: "^0.2.0+1" get the package, and build the app flutter packages get flutter build ios flutter build apk Import the package in your code import 'package:speech_recognition/speech_recognition.dart'; That’s all … unless the plugin does require special permissions, in which case it is necessary to edit the file for iOS, and for Android. .plist manifest.xml Then when the application is build, depending on the OS, Flutter will install and manage the iOS / Android dependencies, so that the native code is properly made available. The team has set up a self-recording plugin system that works wonderfully, and in most cases, you have even not to touch iOS or Android files. 🍾🥂 Build a plugin But the goes even further with the tooling to create plugins ! I found it so effective that I already published 4 plugins, while the least I can say, is that I was not at all a crossplatform plugin expert :). magnificence The Flutter CLI provides a plugin scaffold generation command, containing all the necessary files, and even a pre-configured sample project using the created plugin : flutter create -i swift --org bz.rxla --plugin my_plugin : we want to use Swift for the iOS code, and not ObjC defined by default -i swift : if we want to use Kotlin instead of the Java default Android side -a kotlin : plugin namespace --org my.domain : the name of the plugin --plugin my_plugin On the Dart side, the generated code is very simple, it mainly contains the creation of a “dedicated” channel. The most interesting aspect of this system is the self-detection / installation of plugins on iOS and Android. Flutter / Dart Here is the code generated for the Dart part of a plugin: iOS / Swift The file contains the mechanism that allows an application to auto-detect the plugin. It’s a static method, called by the application at launch to transmit a . The registrar role is to add the channel created by the plugin to the list of "receivers" of calls, to enable it to receive calls via its method. SwiftPluginDemoPlugin.swift register FlutterPluginRegistrar MethodChannel handle The use of Swift adds a small layer, with the generation of both ObjC and files, and a . PluginDemoPlugin.h .m SwiftPluginDemoPlugin.swift Android / Java We find the same principle of in Java for Android. registrar Implementation From there, all that remains is to “move” the implementation from to the plugin project, as well as the associated Swift and Java code. cf. the second part Speech_recognition plugin Publish To publish a plugin on pub.dartlang.com : /FLUTTER_PATH/bin/cache/dart-sdk/bin/pub publish Resources Documentation The Sytody app Speech_recognition plugin Flutter plugins and packages