Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding Flutter Plugins, The Federated Way

Avatar for Smit Sonani Smit Sonani
September 25, 2021

Understanding Flutter Plugins, The Federated Way

Most of the time we are dependent on some framework or libraries for building the software & Flutter apps are no exception to it. In this talk we will understand the fundamentals of such a library or framework (known as Packages / Plugins in Flutter ecosystem). Besides this we will explore more scalable solutions to build packages which support multiple platforms. Also we will shed light on some common How-tos like: debug, test, versioning & publishing of Plugins.

Avatar for Smit Sonani

Smit Sonani

September 25, 2021

Other Decks in Technology

Transcript

  1. 🗺 Roadmap • Packages & Plugins • Federated Plugins •

    Communication • Create Federated Plugins • Android Embedding v2 • 🔌 In Action • Publish Plugins • Key Takeaways
  2. Packages ◦ Reusability - reduces the efforts of solving the

    same problem. ◦ Comprehensive maintainability ◦ Might not need platform features, can be pure Dart. Plugins ◦ A special type of package which makes platform features available to the app ◦ Requires native platform implementation skills
  3. Overview • Divides responsibilities into primarily 3 layers ◦ Platform

    Interface package ◦ App-facing package ◦ Platform specific plugin • Easy to collaborate with, domain experts can take care of specific platform plugin • Easy to support multiple platforms • Endorsed vs. Non-Endorsed
  4. App-Facing Package • Exposes the features of the plugins to

    the Flutter app. • This package goes as a dependency in the app. • Pure Dart • Depends on Platform Interface package & Platform Plugin packages • Should contain an example app demonstrating features provided by the plugin.
  5. Platform Interface • Acts as a common interface between app-facing

    package & platform specific plugins. • The default implementation for Platform Channels goes in this package. • Pure Dart • Depends on plugin_platform_interface
  6. • Implements platform specific features at native side • Requires

    platform specific development skills • The web plugin is an exception. It can be written in Dart which compiles to JS. Platform Plugin(s)
  7. Key Components • Channel ◦ A bridge between the Flutter

    app & the platform ◦ Bidirectional message passing • Codec ◦ Encodes & Decodes data being sent via channel ◦ Default - StandardMessageCodec • Messenger ◦ Sends data via channel ◦ BinaryMessenger
  8. Types of Channels • MethodChannel ◦ One time operations ◦

    Use cases ▪ Get something from the platform or vice-versa ▪ Trigger something on the platform or vice-versa ◦ OptionalMethodChannel • EventChannel ◦ Streaming data from a platform to the Flutter app. ◦ Use cases ▪ Continuously listen for updates from platform side. i.e. location changes
  9. Pigeon • A code gen tool for better type safe

    communication • Uses StandardMessageCodec • Supports Android & iOS only at moment • Created by Flutter team • Example
  10. Best Practices [based on pub.dev - score] • Provide valid

    files: pubspec.yaml, README.md, CHANGELOG.md • Documentation of public methods • Supports multi-platform [For app facing package] • Code has no errors, warnings, lints, or formatting issues • Dependencies should be up-to-date • Null-Safe
  11. Key Takeaways • Method Channels for one time operations •

    Event Channels for streaming data from platform side • Android embedding v2 for better lifecycle management • FlutterApplicationLifeCycleDelegate for iOS app lifecycle • example app for development, debugging & testing the native code • Don’t forget to --dry-run before publishing to pub.dev
  12. Useful Links • Packages & Plugins • Modern Flutter Plugin

    Development • Supported Devices - Demo Plugin