text
stringlengths
1
372
in the pubspec for the app-facing package.
then, when a developer includes the foobar plugin
in their flutter app, the windows implementation,
as well as the other endorsed implementations,
are automatically available to the app.
<topic_end>
<topic_start>
non-endorsed federated plugin
if you can’t, for whatever reason, get your implementation
added by the original plugin author, then your plugin
is not endorsed. a developer can still use your
implementation, but must manually add the plugin
to the app’s pubspec file. so, the developer
must include both the foobar dependency and
the foobar_windows dependency in order to achieve
full functionality.
for more information on federated plugins,
why they are useful, and how they are
implemented, see the medium article by harry terkelsen,
how to write a flutter web plugin, part 2.
<topic_end>
<topic_start>
specifying a plugin’s supported platforms
plugins can specify the platforms they support by
adding keys to the platforms map in the
pubspec.yaml file. for example,
the following pubspec file shows the
flutter: map for the hello plugin,
which supports only iOS and android:
when adding plugin implementations for more platforms,
the platforms map should be updated accordingly.
for example, here’s the map in the pubspec file
for the hello plugin,
when updated to add support for macOS and web:
<topic_end>
<topic_start>
federated platform packages
a platform package uses the same format,
but includes an implements entry indicating
which app-facing package it implements. for example,
a hello_windows plugin containing the windows
implementation for hello
would have the following flutter: map:
<topic_end>
<topic_start>
endorsed implementations
an app facing package can endorse a platform package by adding a
dependency on it, and including it as a default_package in the
platforms: map. if the hello plugin above endorsed hello_windows,
it would look as follows:
note that as shown here, an app-facing package can have
some platforms implemented within the package,
and others in endorsed federated implementations.
<topic_end>
<topic_start>
shared iOS and macOS implementations
many frameworks support both iOS and macOS with identical
or mostly identical APIs, making it possible to implement
some plugins for both iOS and macOS with the same codebase.
normally each platform’s implementation is in its own
folder, but the sharedDarwinSource option allows iOS
and macOS to use the same folder instead:
when sharedDarwinSource is enabled, instead of
an ios directory for iOS and a macos directory
for macOS, both platforms use a shared darwin
directory for all code and resources. when enabling
this option, you need to move any existing files
from ios and macos to the shared directory. you
also need to update the podspec file to set the
dependencies and deployment targets for both platforms,
for example:
<topic_end>
<topic_start>
step 1: create the package
to create a plugin package, use the --template=plugin
flag with flutter create.
use the --platforms= option followed by a
comma-separated list to specify the platforms
that the plugin supports. available platforms are:
android, ios, web, linux, macos, and windows.
if no platforms are specified, the
resulting project doesn’t support any platforms.
use the --org option to specify your organization,
using reverse domain name notation. this value is used
in various package and bundle identifiers in the
generated plugin code.
use the -a option to specify the language for android
or the -i option to specify the language for ios.
please choose one of the following:
this creates a plugin project in the hello folder
with the following specialized content:
by default, the plugin project uses swift for iOS code and
kotlin for android code. if you prefer Objective-C or java,
you can specify the iOS language using -i and the
android language using -a. for example:
<topic_end>
<topic_start>
step 2: implement the package
as a plugin package contains code for several platforms
written in several programming languages,