This guide describes how Flutter apps can integrate with platform-specific code available on iOS and Android devices. This includes both device APIs (like Clipboard and BatteryState) and third-party platform SDKs (like Google Analytics).

Options for integrating with platform-specific code

Mobile devices offer many options to extend your app through platform-specific APIs. These are critical to the completeness of most mobile apps. Flutter offers the following ways to integrate with these via plugins, packages that contain an API definition written in Dart, coupled with a platform-specific implementation for Android, for iOS, or for both.

There are two ways you can use platform-specific code:

  • Use existing platform plugins: For frequently used APIs and SDKs, use existing platform plugins, with no need to write any platform-specific code. See details below.

  • Write custom platform code: Write your own platform-specific code using Flutter’s platform channels. This can be used for private APIs, or for cases where a suitable platform plugin is not yet available. See the platform channels page for details.

And, if desired, you can create and share plugins:

  • Create a platform plugin If you wish to use your platform-specific code in multiple Flutter apps, or share it with others, then you can wrap it in a plugin. See details below

  • Publish a platform plugin: Publish custom platform-specific code as a plugin. This enables other developers to use it by simply declaring a dependency on the plugin. See details below.

Use existing platform plugins

Core Flutter platform plugin

The Flutter framework includes a core platform plugin for foundational platform-specific services, such as:

  • Clipboard: Utility methods for interacting with the system’s clipboard.

  • SystemSound: Provides access to the library of short system specific sounds for common tasks.

  • PathProvider: Returns commonly used locations on the filesystem.

See the services library for full details.

Example: Using the Flutter platform plugin to read the contents of the Clipboard

The core Flutter platform plugin is available through the services library, as illustrated in this example:

import 'package:flutter/services.dart';

class _MyHomePageState extends State<MyHomePage> {
 String clipboardContents = 'Unknown';

 getClipboardContents() async {
   var clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
   if (clipboardData != null) {
     setState(() {
       clipboardContents = clipboardData.text;
     });
   }
 }

 // clipboardContents can now be accessed in the build() method.
}

Platform plugins from the Flutter ecosystem

Create a platform plugin

If you expect to use your platform-specific code in multiple Flutter apps, it can be useful to separate the code into a platform plugin located in a directory outside your main application. Optionally, this also enables you to publish the plugin.

Publish a platform plugin