Modern Flutter Plugin Development
Article Summary
Chris Sells and the Flutter team just dropped a masterclass on plugin architecture. If you're still using MethodChannels the old way, you're about to feel very behind.
The Flutter team published a comprehensive guide to modern plugin development in 2020, introducing Android Plugin API 2.0, federated plugins, and a new pubspec schema. This marked a fundamental shift in how Flutter plugins are architected across multiple platforms.
Key Takeaways
- Android Plugin API 2.0 replaces static initialization with lifecycle-aware attachment/detachment
- New pubspec schema explicitly declares platform support (Android, iOS, web, macOS, Windows, Linux)
- Federated plugins split implementations across packages, enabling platform-specific expertise
- Platform interface packages replace MethodChannels as the glue between app-facing and platform code
- ActivityAware interface handles Android lifecycle events and configuration changes properly
Flutter plugins now support proper lifecycle management, explicit platform declarations, and federated architecture that lets multiple teams contribute platform-specific implementations without bottlenecks.
About This Article
Flutter plugins needed to initialize statically and couldn't handle multiple FlutterEngine instances at the same time. This meant all plugins had to start up when the app launched, even if they weren't needed right away.
Chris Sells and the Flutter team built the FlutterPlugin interface with onAttachedToFlutterEngine() and onDetachedFromFlutterEngine() callbacks. Plugins could now load only when required and attach to specific engine instances.
Plugins can attach and detach multiple times as an app runs. This opened up more complex scenarios, like running several Flutter experiences at once inside a single Android application.