0PricingLogin
Flutter Mobile Development · Lesson

Writing Custom Platform Plugins for iOS and Android

Author federated plugins exposing native Kotlin and Swift APIs to Dart.

Why Platform Plugins?

Dart cannot call native iOS or Android APIs directly. A platform plugin bridges that gap, exposing Swift/Objective-C and Kotlin/Java capabilities to your Dart code through a typed channel.

  • Package: pure Dart, no native code.
  • Plugin: Dart API plus platform-specific native implementations.

You write a plugin whenever you need hardware (sensors, BLE), OS services (notifications, keychain), or a native SDK that has no Dart equivalent. In this lesson we author a federated plugin that surfaces native Kotlin and Swift APIs to Dart.

Federated Plugin Architecture

A federated plugin splits responsibilities across several packages so different parties can own different platforms:

  • app-facing package (battery): the public Dart API developers import.
  • platform interface (battery_platform_interface): an abstract contract all implementations must satisfy.
  • platform packages (battery_android, battery_ios): concrete native implementations registered via pubspec.yaml.

This decoupling lets a third party add, say, a Windows implementation without touching the app-facing package. The interface package is the linchpin contract.

All lessons in this course

  1. Calling C Libraries with dart:ffi
  2. Type-Safe Platform Channels with Pigeon
  3. Writing Custom Platform Plugins for iOS and Android
  4. Background Isolates and Native Memory Management
← Back to Flutter Mobile Development