text stringlengths 1 474 |
|---|
), |
); |
} |
}<code_end> |
Run the app (or stop and restart it, if it was already running |
before adding the plugin). Click Show Flutter homepage. |
You should see the default browser open on the device, |
displaying the homepage for flutter.dev. |
<topic_end> |
<topic_start>Developing packages & plugins |
<topic_end> |
<topic_start> |
Package introduction |
Packages enable the creation of modular code that can be shared easily. |
A minimal package consists of the following:info Note |
For a list of dos and don’ts when writing an effective plugin, |
see the Medium article by Mehmet Fidanboylu, |
Writing a good plugin.<topic_end> |
<topic_start> |
Package types |
Packages can contain more than one kind of content:Plugin packages can be written for Android |
(using Kotlin or Java), iOS (using Swift or Objective-C), |
web, macOS, Windows, or Linux, or any combination |
thereof.A concrete example is the url_launcher plugin package. |
To see how to use the url_launcher package, and how it |
was extended to implement support for web, |
see the Medium article by Harry Terkelsen, |
How to Write a Flutter Web Plugin, Part 1.<topic_end> |
<topic_start> |
Developing Dart packages |
The following instructions explain how to write a Flutter |
package.<topic_end> |
<topic_start> |
Step 1: Create the package |
To create a starter Flutter package, |
use the --template=package flag with flutter create:This creates a package project in the hello |
folder with the following content:<topic_end> |
<topic_start> |
Step 2: Implement the package |
For pure Dart packages, simply add the functionality |
inside the main lib/<package name>.dart file, |
or in several files in the lib directory.To test the package, add unit tests |
in a test directory.For additional details on how to organize the |
package contents, |
see the Dart library package documentation.<topic_end> |
<topic_start> |
Developing plugin packages |
If you want to develop a package that calls into |
platform-specific APIs, |
you need to develop a plugin package.The API is connected to the platform-specific |
implementation(s) using a platform channel.<topic_end> |
<topic_start> |
Federated plugins |
Federated plugins are a way of splitting support for |
different platforms into separate packages. |
So, a federated plugin can use one package for iOS, |
another for Android, another for web, |
and yet another for a car (as an example of an IoT device). |
Among other benefits, this approach allows a domain expert |
to extend an existing plugin to work for the platform they know best.A federated plugin requires the following packages:<topic_end> |
<topic_start>Endorsed federated plugin |
Ideally, when adding a platform implementation to |
a federated plugin, you will coordinate with the package |
author to include your implementation. |
In this way, the original author endorses your |
implementation.For example, say you write a foobar_windows |
implementation for the (imaginary) foobar plugin. |
In an endorsed plugin, the original foobar author |
adds your Windows implementation as a dependency |
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, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.