In their Flutter app, the Windows implementation,Īs well as the other endorsed implementations,Īre automatically available to the app. Then, when a developer includes the foobar plugin In the pubspec for the app-facing package. In an endorsed plugin, the original foobar authorĪdds your Windows implementation as a dependency Implementation for the (imaginary) foobar plugin. In this way, the original author endorses yourįor example, say you write a foobar_windows Ideally, when adding a platform implementation toĪ federated plugin, you will coordinate with the package Packages implement the same functionality in a uniform way. That defines this interface ensures that all platform Interface that any platform package must implement to platform interface package The package that glues the app-facing packing Unless they contain platform-specific functionalityĪccessible to the end user. These packages-they aren’t included into an app, platform package(s) One or more packages that contain the platform-specific This package specifies the API used by the Flutter app. Among other benefits, this approach allows a domain expert to extend anĮxisting plugin to work for the platform they know best.Ī federated plugin requires the following packages: app-facing package The package that plugin users depend on to use the plugin. So, a federated plugin can use one package for iOS, anotherįor Android, another for web, and yet another for a car (as an example of an IoTĭevice). The API is connected to the platform-specific implementation(s) using aįederated plugins are a way of splitting support for different platforms into If you want to develop a package that calls into platform-specific APIs, you See the Dart library package documentation.
Or in several files in the lib directory.įor additional details on how to organize the Step 2: Implement the packageįor pure Dart packages, simply add the functionality CHANGELOG.md A (mostly) empty markdown file for tracking idea/workspace.xml A hidden folder containing configuration filesįor the IntelliJ IDEs.
lib/hello.dart A starter app containing Dart code for the package.idea/modules.xml. README.md A starter markdown file that briefly describes pubspec.yaml A yaml file containing metadata that specifies hello.iml A configuration file used by the IntelliJ IDEs.gitignore A hidden file that tells Git which files orįolders to ignore in a tadata A hidden file used by IDEs to track the properties test/hello_test.dart The unit tests for the package.
This creates a package project in the helloįolder with the following content: LICENSE A (mostly) empty license text file. $ flutter create -template =package hello To create a Flutter package, use the -template=package flag The following instructions explain how to write a Flutter How to Write a Flutter Web Plugin, Part 1. See the Medium article by Harry Terkelsen, Was extended to implement support for web, To see how to use the url_launcher package, and how it Swift or Objective-C), web, macOS, Windows, or Linux, or any combinationĪ concrete example is the url_launcher plugin package.
Plugin packages can be written for Android (using Kotlin or Java), iOS (using Plugin packages A specialized Dart package that contains an API written inĭart code combined with one or more platform-specific Some of these might contain Flutter specificįunctionality and thus have a dependency on theįlutter framework, restricting their use to Flutter only,įor example the fluro package. Packages can contain more than one kind of content: Dart packages General packages written in Dart, See the Medium article by Mehmet Fidanboylu, dart file.įor a list of dos and don’ts when writing an effective plugin, lib The lib directory contains the public code in Minimal package consists of the following: pubspec.yaml A metadata file that declares the package name, Packages enable the creation of modular code that can be shared easily.
For information on how to upgrade your plugin, see Supporting the newĪndroid plugins APIs. Will see a warning when the framework detects that you are using an old-style Indicate which platforms a plugin supports, for exampleĮventually, the old plugin APIs will be deprecated.
The plugin API has been updated and now supports federated plugins thatĮnable separation of different platform implementations.
Step 2c: Add iOS platform code (.swift/.h+.m).Step 2b: Add Android platform code (.kt/.java).Step 2a: Define the package API (.dart).Specifying a plugin’s supported platforms.