p-hatan/ mirror

pub repository

mirror.p-hatan.com

plugin_platform_interface

2.1.8

Reusable base class for platform interfaces of Flutter federated plugins, to help enforce best practices.

Cached in Iran · Upstream SHA-256 matched

Download archive

Readme

plugin_platform_interface

This package provides a base class for platform interfaces of federated flutter plugins.

Platform implementations should extends their platform interface class rather than implements it, as newly added methods to platform interfaces are not considered breaking changes. Extending a platform interface ensures that subclasses will get the default implementations from the base class, while platform implementations that implements their platform interface will be broken by newly added methods.

This class package provides common functionality for platform interface to enforce that they are extended and not implemented.

Sample usage:

abstract class SamplePluginPlatform extends PlatformInterface {
  SamplePluginPlatform() : super(token: _token);

  static final Object _token = Object();

  // A plugin can have a default implementation, as shown here, or `instance`
  // can be nullable, and the default instance can be null.
  static SamplePluginPlatform _instance = SamplePluginDefault();

  static SamplePluginPlatform get instance => _instance;

  /// Platform-specific implementations should set this to their own
  /// platform-specific class that extends [SamplePluginPlatform] when they
  /// register themselves.
  static set instance(SamplePluginPlatform instance) {
    PlatformInterface.verify(instance, _token);
    _instance = instance;
  }

  // Methods for the plugin's platform interface would go here, often with
  // implementations that throw UnimplementedError.
}

class SamplePluginDefault extends SamplePluginPlatform {
  // A default real implementation of the platform interface would go here.
}

This guarantees that UrlLauncherPlatform.instance cannot be set to an object that implements UrlLauncherPlatform (it can only be set to an object that extends UrlLauncherPlatform).

Mocking or faking platform interfaces

Test implementations of platform interfaces, such as those using mockito's Mock or test's Fake, will fail the verification done by verify. This package provides a MockPlatformInterfaceMixin which can be used in test code only to disable the extends enforcement.

For example, a Mockito mock of a platform interface can be created with:

class SamplePluginPlatformMock extends Mock
    with MockPlatformInterfaceMixin
    implements SamplePluginPlatform {}

A note about base

In Dart 3, the base keyword was introduced to the language, which enforces that subclasses use extends rather than implements at compile time. The Flutter team is considering deprecating this package in favor of using base for platfom interfaces, but no decision has been made yet since it removes the ability to do mocking/faking as shown above.

Plugin authors may want to consider using base instead of this package when creating new plugins.

https://github.com/flutter/flutter/issues/127396

Changelog

2.1.8

  • Fixes new lint warnings.

2.1.7

  • Changes MockPlatformInterfaceMixin to a mixin class for better compatibility with projects that have a minumum Dart SDK version of 3.0.
  • Updates minimum supported SDK version to Dart 3.0.

2.1.6

  • Adds pub topics to package metadata.
  • Updates minimum supported SDK version to Flutter 3.7/Dart 2.19.

2.1.5

  • Updates README to improve example and discuss base.
  • Updates minimum Flutter version to 3.3.

2.1.4

  • Updates links for the merge of flutter/plugins into flutter/packages.
  • Updates minimum supported Dart version.

2.1.3

  • Minor fixes for new analysis options.
  • Adds additional tests for PlatformInterface and MockPlatformInterfaceMixin.
  • Modifies PlatformInterface to use an expando for detecting if a customer tries to implement PlatformInterface using implements rather than extends. This ensures that verify will continue to work as advertized after https://github.com/dart-lang/language/issues/2020 is implemented.

2.1.2

  • Updates README to demonstrate verify rather than verifyToken, and to note that the test mixin applies to fakes as well as mocks.
  • Adds an additional test for verifyToken.

2.1.1

  • Fixes verify to work with fake objects, not just mocks.

2.1.0

  • Introduce verify, which prevents use of const Object() as instance token.
  • Add a comment indicating that verifyToken will be deprecated in a future release.

2.0.2

  • Update package description.

2.0.1

  • Fix federated flutter plugins link in the README.md.

2.0.0

  • Migrate to null safety.

1.0.3

  • Fix homepage in pubspec.yaml.

1.0.2

  • Make the pedantic dev_dependency explicit.

1.0.1

1.0.0 - Initial release.

  • Provides PlatformInterface with common mechanism for enforcing that a platform interface is not implemented with implements.
  • Provides test only MockPlatformInterface to enable using Mockito to mock platform interfaces.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add plugin_platform_interface
pubspec.yaml
name: plugin_platform_interface
description: Reusable base class for platform interfaces of Flutter federated
  plugins, to help enforce best practices.
repository: https://github.com/flutter/packages/tree/main/packages/plugin_platform_interface
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+plugin_platform_interface%22

# DO NOT MAKE A BREAKING CHANGE TO THIS PACKAGE
# DO NOT INCREASE THE MAJOR VERSION OF THIS PACKAGE
#
# This package is used as a second level dependency for many plugins, a major version bump here
# is guaranteed to lead the ecosystem to a version lock (the first plugin that upgrades to version
# 3 of this package cannot be used with any other plugin that have not yet migrated).
#
# Please consider carefully before bumping the major version of this package, ideally it should only
# be done when absolutely necessary and after the ecosystem has already migrated to 2.X.Y version
# that is forward compatible with 3.0.0 (ideally the ecosystem have migrated to depend on:
# `plugin_platform_interface: >=2.X.Y <4.0.0`).
version: 2.1.8

environment:
  sdk: ">=3.0.0 <4.0.0"

dependencies:
  meta: ^1.3.0

dev_dependencies:
  mockito: 5.4.3
  test: ^1.16.0

topics:
  - federation
  - plugin-development

Version history

VersionPublishedArchiveSHA-256
1.0.02019-12-11T00:12:33.520577ZCachedc768206302b0141ee3ce929962a5af9dce21dc3d87f8f9fa5e9a86cb0399294d
1.0.12019-12-13T20:33:30.957322ZCached98112433d3a6effdf61a6940293de4ff335942932f323877a835fe8075030931
1.0.22020-02-21T00:01:58.068536ZCached3c3d17d0012f7388b8beb79a4517cd2f25b66aa09f9f99f9adcaada6ea6f46f1
1.0.32020-09-29T21:50:13.348795ZCachedc3ebbff365bfb1b5f7b690c9857d2dabea167f35b05eb7586186499b407efb37
1.1.0-nullsafety2020-10-28T01:50:46.990235ZCached3026b8c7537be072ccebc52f41eda7e6f36da0dbc69906fe7555f1c2a54d9324
1.1.0-nullsafety.12020-11-05T00:13:39.158364ZCached8c6a02f6761b6d8c5845225aff6689b5a2544702b9d7db655cd46a3b47528598
1.1.0-nullsafety.22021-02-01T19:45:55.531013ZCachedb659c628f1d29369371b0e4e334beb3606474f4f3bcf887975926d7f7643b563
2.0.02021-02-18T22:29:46.158746ZCachedc2c49e16d42fd6983eb55e44b7f197fdf16b4da7aab7f8e1d21da307cad3fb02
2.0.12021-07-08T07:35:53.994525ZCached5aadc2af7cd403ad0b95ef654c3e628517f4cae9682b4229a66caf9df71844d2
2.0.22021-09-30T18:51:18.482380ZCachedf843e0027496f0d841166707029237a0bef39cfc0c79b93b1bb1a10beae73244
2.1.02022-01-06T02:16:01.769147ZCachedc384b19bf8d317b3d1576327203cdc95f96bf5f109ab63ab72690fe32fdb0d3c
2.1.12022-01-07T18:04:22.273001ZCached6fe9d6dbfff24839a5d4973e647628921873f471ae90f4bb6e72c8f67d757699
2.1.22022-01-08T00:38:42.507785ZCached075f927ebbab4262ace8d0b283929ac5410c0ac4e7fc123c76429564facfb757
2.1.32022-09-15T17:41:17.026252ZCacheddbf0f707c78beedc9200146ad3cb0ab4d5da13c246336987be6940f026500d3a
2.1.42023-02-22T20:36:30.219631ZCached6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc
2.1.52023-07-20T21:54:42.354911ZCached43798d895c929056255600343db8f049921cbec94d31ec87f1dc5c16c01935dd
2.1.62023-08-30T15:08:36.570873ZCachedda3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d
2.1.72023-11-17T21:13:01.146066ZCachedf4f88d4a900933e7267e2b353594774fc0d07fb072b47eedcd5b54e1ea3269f8
2.1.82024-01-04T03:51:50.934076ZCached4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02

Dependencies

meta "^1.3.0"