flutter-native-bridge-ffi
Step 6 of the pipeline (WORKFLOW.md), for the boundary between Dart and the platform's own language. The
premise: across a language boundary a string name, a message shape or a pointer's lifetime is checked by
nothing the compiler owns, so the boundary is generated where it can be, typed where it cannot, and kept in
one place. Permissions and platform prompts are flutter-conventions §8; reading untrusted data that
crosses the boundary is security-hardening; isolates for heavy Dart work are flutter-conventions §2 and
§8.
When
- A feature needs a platform API no existing plugin offers, or wraps a native library.
- A channel call fails on a background thread, returns twice, or silently loses a field after a rename.
- Hand-written
dart:ffi bindings, a DynamicLibrary lookup, or native memory appears in a diff.
- A package needs to compile or bundle native code.
Steps
Read only the section the task meets. They are independent.
| § |
Covers |
Read it when |
File |
| 1 |
Channels versus Pigeon, the generated-code contract, threading, background isolates, replying once, the data a channel can carry, web |
a channel or a generated bridge is written or reviewed |
01-channels-and-pigeon.md |
| 2 |
FFI: when to reach for it, generated bindings, leaf calls, native memory and finalizers, build and link hooks and their Dart floors |
dart:ffi, a native library, or a hook/ directory is involved |
02-ffi-and-hooks.md |
Output / checkpoint
The bridge was exercised end to end on each platform it targets: a call from Dart reached the native side on
the intended thread, returned once, and carried a changed field through both directions after a rename (§1);
for FFI, the generator was re-run and produced no diff, the analyzer was clean, and the native side was
built through the hook, not by hand (§2). A bridge that compiled on one platform is not verified on the
others.
Guardrails
- Never edit a generated file by hand; change the definition and regenerate (§1, §2).
- Never split Pigeon-generated Dart and native code across packages, and never expose Pigeon-generated types
in a public API (§1).
- Never mark a native function as a leaf call unless it neither calls back into Dart nor blocks (§2).
- Never invoke a raw compiler from a hook, and never run a downloaded prebuilt library without checking its
hash (§2).
- Never rely on a native finalizer to release a resource at process exit (§2).
- Versions: each rule names the version of the page or package it was read from. Nothing was built or run
while writing this block.
Origin
Rewritten from the Flutter platform-channels page, the Pigeon README, the Dart ffigen and native-assets
skills of the Flutter agent plugins, the Dart site's hooks page and the dart:ffi API reference, read
2026-10-08. Overlaps with skills/flutter-conventions (2026-10-19); cross-referenced, not merged. 🟡: never run by us; open
points are in references/origin.md.
1---2name: flutter-native-bridge-ffi3description: "Use when Dart code has to call native code: a platform channel or a Pigeon-generated bridge between Flutter and Kotlin, Swift or C++, the thread a channel runs on, a background isolate using a plugin, and dart:ffi (generated bindings, leaf calls, native memory and finalizers, build and link hooks that compile or bundle native code). Covers when to choose which and what must never be edited by hand."4metadata:5 source: https://skillmd.com/skills/techmefr/flutter-native-bridge-ffi6---78# flutter-native-bridge-ffi910Step 6 of the pipeline (`WORKFLOW.md`), for the boundary between Dart and the platform's own language. The11premise: **across a language boundary a string name, a message shape or a pointer's lifetime is checked by12nothing the compiler owns, so the boundary is generated where it can be, typed where it cannot, and kept in13one place**. Permissions and platform prompts are `flutter-conventions` §8; reading untrusted data that14crosses the boundary is `security-hardening`; isolates for heavy Dart work are `flutter-conventions` §2 and15§8.1617## When18- A feature needs a platform API no existing plugin offers, or wraps a native library.19- A channel call fails on a background thread, returns twice, or silently loses a field after a rename.20- Hand-written `dart:ffi` bindings, a `DynamicLibrary` lookup, or native memory appears in a diff.21- A package needs to compile or bundle native code.2223## Steps2425**Read only the section the task meets.** They are independent.2627| § | Covers | Read it when | File |28|---|---|---|---|29| 1 | Channels versus Pigeon, the generated-code contract, threading, background isolates, replying once, the data a channel can carry, web | a channel or a generated bridge is written or reviewed | [`01-channels-and-pigeon.md`](./references/01-channels-and-pigeon.md) |30| 2 | FFI: when to reach for it, generated bindings, leaf calls, native memory and finalizers, build and link hooks and their Dart floors | `dart:ffi`, a native library, or a `hook/` directory is involved | [`02-ffi-and-hooks.md`](./references/02-ffi-and-hooks.md) |3132## Output / checkpoint33The bridge was exercised end to end on each platform it targets: a call from Dart reached the native side on34the intended thread, returned once, and carried a changed field through both directions after a rename (§1);35for FFI, the generator was re-run and produced no diff, the analyzer was clean, and the native side was36built through the hook, not by hand (§2). A bridge that compiled on one platform is not verified on the37others.3839## Guardrails40- Never edit a generated file by hand; change the definition and regenerate (§1, §2).41- Never split Pigeon-generated Dart and native code across packages, and never expose Pigeon-generated types42 in a public API (§1).43- Never mark a native function as a leaf call unless it neither calls back into Dart nor blocks (§2).44- Never invoke a raw compiler from a hook, and never run a downloaded prebuilt library without checking its45 hash (§2).46- Never rely on a native finalizer to release a resource at process exit (§2).47- Versions: each rule names the version of the page or package it was read from. Nothing was built or run48 while writing this block.4950## Origin51Rewritten from the Flutter platform-channels page, the Pigeon README, the Dart ffigen and native-assets52skills of the Flutter agent plugins, the Dart site's hooks page and the `dart:ffi` API reference, read532026-10-08. Overlaps with `skills/flutter-conventions` (2026-10-19); cross-referenced, not merged. 🟡: never run by us; open54points are in [`references/origin.md`](./references/origin.md).