plugin_platform_interface 1.0.2

  • Readme
  • Changelog
  • Installing
  • 94

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 {}

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.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  plugin_platform_interface: ^1.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:plugin_platform_interface/plugin_platform_interface.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
100
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
69
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on Apr 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/flutter/plugins/plugin_platform_interface was unreachable.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and plugin_platform_interface.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

The package description is too short. (-1 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
meta ^1.0.0 1.1.8
Dev dependencies
mockito ^4.1.1
pedantic ^1.8.0
test ^1.9.4