text stringlengths 1 474 |
|---|
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, |
some specific steps are needed to ensure a smooth experience.<topic_end> |
<topic_start>Step 2a: Define the package API (.dart) |
The API of the plugin package is defined in Dart code. |
Open the main hello/ folder in your favorite Flutter editor. |
Locate the file lib/hello.dart.<topic_end> |
<topic_start>Step 2b: Add Android platform code (.kt/.java) |
We recommend you edit the Android code using Android Studio.Then use the following steps:The Android platform code of your plugin is located in |
hello/java/com.example.hello/HelloPlugin.You can run the example app from Android Studio by |
pressing the run (▶) button.<topic_end> |
<topic_start>Step 2c: Add iOS platform code (.swift/.h+.m) |
We recommend you edit the iOS code using Xcode.Before editing the iOS platform code in Xcode, |
first make sure that the code has been built at least once |
(in other words, run the example app from your IDE/editor, |
or in a terminal execute |
cd hello/example; flutter build ios --no-codesign).Then use the following steps:The iOS platform code for your plugin is located in |
Pods/Development Pods/hello/../../example/ios/.symlinks/plugins/hello/ios/Classes |
in the Project Navigator. (If you are using sharedDarwinSource, |
the path will end with hello/darwin/Classes instead.)You can run the example app by pressing the run (▶) button.<topic_end> |
<topic_start>Add CocoaPod dependencies |
Use the following instructions to add HelloPod with the version 0.0.1:Specify dependency at the end of ios/hello.podspec:For private pods, refer to Private CocoaPods to ensure repo access:Installing the pluginThe pod should appear in the installation summary.<topic_end> |
<topic_start>Step 2d: Add Linux platform code (.h+.cc) |
We recommend you edit the Linux code using an IDE with |
C++ integration. The instructions below are for |
Visual Studio Code with the “C/C++” and “CMake” extensions |
installed, but can be adjusted for other IDEs.Before editing the Linux platform code in an IDE, |
first make sure that the code has been built at least once |
(in other words, run the example app from your Flutter |
IDE/editor, or in a terminal execute |
cd hello/example; flutter build linux).Then use the following steps:The Linux platform code for your plugin is located in |
flutter/ephemeral/.plugin_symlinks/hello/linux/.You can run the example app using flutter run. |
Note: Creating a runnable Flutter application |
on Linux requires steps that are part of the flutter |
tool, so even if your editor provides CMake |
integration building and running that way won’t |
work correctly.<topic_end> |
<topic_start>Step 2e: Add macOS platform code (.swift) |
We recommend you edit the macOS code using Xcode.Before editing the macOS platform code in Xcode, |
first make sure that the code has been built at least once |
(in other words, run the example app from your IDE/editor, |
or in a terminal execute |
cd hello/example; flutter build macos).Then use the following steps:The macOS platform code for your plugin is located in |
Pods/Development Pods/hello/../../example/macos/Flutter/ephemeral/.symlinks/plugins/hello/macos/Classes |
in the Project Navigator. (If you are using sharedDarwinSource, |
the path will end with hello/darwin/Classes instead.)You can run the example app by pressing the run (▶) button.<topic_end> |
<topic_start>Step 2f: Add Windows platform code (.h+.cpp) |
We recommend you edit the Windows code using Visual Studio.Before editing the Windows platform code in Visual Studio, |
first make sure that the code has been built at least once |
(in other words, run the example app from your IDE/editor, |
or in a terminal execute |
cd hello/example; flutter build windows).Then use the following steps:The Windows platform code for your plugin is located in |
hello_plugin/Source Files and hello_plugin/Header Files in |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.