p-hatan/ mirror

pub repository

mirror.p-hatan.ir

plugin_platform_interface

2.0.1

Reusable base class for Flutter plugin platform interfaces.

Download archive

Readme

plugin_platform_interface

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

Platform implementations should extend their platform interface classes rather than implement it as newly added methods to platform interfaces are not considered as 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 UrlLauncherPlatform extends PlatformInterface {
  UrlLauncherPlatform() : super(token: _token);

  static UrlLauncherPlatform _instance = MethodChannelUrlLauncher();

  static final Object _token = Object();

  static UrlLauncherPlatform get instance => _instance;

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

 }

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 platform interfaces with Mockito

Mockito mocks of platform interfaces will fail the verification done by verifyToken. This package provides a MockPlatformInterfaceMixin which can be used in test code only to disable the extends enforcement.

A Mockito mock of a platform interface can be created with:

class UrlLauncherPlatformMock extends Mock
   with MockPlatformInterfaceMixin
   implements UrlLauncherPlatform {}
Changelog

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.ir
flutter pub add plugin_platform_interface
pubspec.yaml
name: plugin_platform_interface
description: Reusable base class for Flutter plugin platform interfaces.
repository: https://github.com/flutter/plugins/tree/master/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
# 2 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 1.X.Y version
# that is forward compatible with 2.0.0 (ideally the ecosystem have migrated to depend on:
# `plugin_platform_interface: >=1.X.Y <3.0.0`).
version: 2.0.1

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  meta: ^1.3.0

dev_dependencies:
  mockito: ^5.0.0
  test: ^1.16.0
  pedantic: ^1.10.0

Version history

VersionPublishedArchiveSHA-256
1.0.02019-12-11T00:12:33.520577ZDownloadc768206302b0141ee3ce929962a5af9dce21dc3d87f8f9fa5e9a86cb0399294d
1.0.12019-12-13T20:33:30.957322ZDownload98112433d3a6effdf61a6940293de4ff335942932f323877a835fe8075030931
1.0.22020-02-21T00:01:58.068536ZDownload3c3d17d0012f7388b8beb79a4517cd2f25b66aa09f9f99f9adcaada6ea6f46f1
1.0.32020-09-29T21:50:13.348795ZDownloadc3ebbff365bfb1b5f7b690c9857d2dabea167f35b05eb7586186499b407efb37
1.1.0-nullsafety2020-10-28T01:50:46.990235ZDownload3026b8c7537be072ccebc52f41eda7e6f36da0dbc69906fe7555f1c2a54d9324
1.1.0-nullsafety.12020-11-05T00:13:39.158364ZDownload8c6a02f6761b6d8c5845225aff6689b5a2544702b9d7db655cd46a3b47528598
1.1.0-nullsafety.22021-02-01T19:45:55.531013ZDownloadb659c628f1d29369371b0e4e334beb3606474f4f3bcf887975926d7f7643b563
2.0.02021-02-18T22:29:46.158746ZDownloadc2c49e16d42fd6983eb55e44b7f197fdf16b4da7aab7f8e1d21da307cad3fb02
2.0.12021-07-08T07:35:53.994525ZDownload5aadc2af7cd403ad0b95ef654c3e628517f4cae9682b4229a66caf9df71844d2
2.0.22021-09-30T18:51:18.482380ZDownloadf843e0027496f0d841166707029237a0bef39cfc0c79b93b1bb1a10beae73244
2.1.02022-01-06T02:16:01.769147ZDownloadc384b19bf8d317b3d1576327203cdc95f96bf5f109ab63ab72690fe32fdb0d3c
2.1.12022-01-07T18:04:22.273001ZDownload6fe9d6dbfff24839a5d4973e647628921873f471ae90f4bb6e72c8f67d757699
2.1.22022-01-08T00:38:42.507785ZDownload075f927ebbab4262ace8d0b283929ac5410c0ac4e7fc123c76429564facfb757
2.1.32022-09-15T17:41:17.026252ZDownloaddbf0f707c78beedc9200146ad3cb0ab4d5da13c246336987be6940f026500d3a
2.1.42023-02-22T20:36:30.219631ZDownload6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc
2.1.52023-07-20T21:54:42.354911ZDownload43798d895c929056255600343db8f049921cbec94d31ec87f1dc5c16c01935dd
2.1.62023-08-30T15:08:36.570873ZDownloadda3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d
2.1.72023-11-17T21:13:01.146066ZDownloadf4f88d4a900933e7267e2b353594774fc0d07fb072b47eedcd5b54e1ea3269f8
2.1.82024-01-04T03:51:50.934076ZDownload4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02

Dependencies

meta "^1.3.0"