Skip to content
pubscout

plugin_platform_interface

2.1.8, released 3 years ago by flutter.dev

Reusable base class for platform interfaces of Flutter federated plugins.

WASM-readyQuiet but busy
$ flutter pub add plugin_platform_interface
Source repository

What it does

Provides a base class and verification mechanism for platform interfaces of federated Flutter plugins. It enforces that platform implementations extend rather than implement the interface, ensuring safety when new methods are added.

AI-written summary of version 2.1.8, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You are developing a federated Flutter plugin
  • You want to enforce that platform implementations extend the platform interface class rather than implement it

Skip it when

  • You are building a standard non-federated app or package
  • You prefer using Dart 3 base classes exclusively for enforcement without runtime checks

Strengths

  • Enforces best practices for federated plugin architecture
  • Provides MockPlatformInterfaceMixin for easy mocking and faking in tests

Weaknesses

  • May be considered redundant in Dart 3 projects that can utilize the `base` class modifier directly

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1

Not documented

abstract class SamplePluginPlatform extends PlatformInterface {
  SamplePluginPlatform() : super(token: _token);
  static final Object _token = Object();
  static SamplePluginPlatform _instance = SamplePluginDefault();
  static SamplePluginPlatform get instance => _instance;
  static set instance(SamplePluginPlatform instance) {
    PlatformInterface.verify(instance, _token);
    _instance = instance;
  }
}

Alternatives

Packages that do the same job and could replace plugin_platform_interface.

Works with

Packages commonly used together with plugin_platform_interface: ones it builds on, ones built on it, and its own family.