# Developing an FFI Plugin

For details, see [Developing FFI Plugin Packages](https://docs.flutter.dev/packages-and-plugins/developing-packages#plugin-ffi).

## 1. Creating a Package

```sh
flutter create --template=plugin_ffi hello --platforms=android,ios,ohos
```

## 2. Building Local Native Code

Specify the platform to use the FFI plugin in the **pubspec.yaml** file as follows:

```yaml
  plugin:
    platforms:
      android:
        ffiPlugin: true
      ohos:
        ffiPlugin: true
      ios:
        ffiPlugin: true
```

## 3. Binding Local Native Code

Bind the local native code in dart to use the code.

To avoid manual compiling, the code is generated by **package:ffigen** in the header file **src/hello.h**. Execute the following instruction to rebind:

```sh
dart run ffigen --config ffigen.yaml
```

## 4. Calling Local Native Code

Local native functions that run for a short time can be directly called in any **isolate**. An example function is **sum** in **lib/hello.dart**.

Local native functions that run for a long time should be called in [helper isolate](https://dart.dev/guides/language/concurrency#background-workers) to avoid frame losses in Flutter applications. An example function is **sumAsync** in **lib/hello.dart**.
