移动开发

flutter-native-interop

flutter/agent-plugins

Interoperate with native APIs in a Flutter app on Android, iOS, and the web

  • 960 次安装
  • 3100 星标
  • 收录于

安装命令

npx skills add https://github.com/flutter/agent-plugins --skill flutter-native-interop

SKILL.md

Flutter Platform Integration

Goal

Integrates Flutter applications with platform-specific code and native features across Android, iOS, and Web environments. Determines the optimal interoperability strategy (FFI, Platform Channels, Platform Views, or JS Interop) and implements the necessary Dart and native code bindings while adhering to thread safety, WebAssembly (Wasm) compatibility, and modern build hook standards.

Instructions

1. Determine Integration Strategy (Decision Logic)

Evaluate the user's requirements using the following decision tree to select the correct integration path:

  • Scenario A: Calling native C/C++ code.
    • Action: Use dart:ffi with the package_ffi template and build hooks.
    • Exception: If accessing the Flutter Plugin API or requiring static linking on iOS, use the legacy plugin_ffi template.
  • Scenario B: Calling OS-specific APIs (Java/Kotlin for Android, Swift/Obj-C for iOS).
    • Action: Use Platform Channels (MethodChannel) or the pigeon package for type-safe code generation.
  • Scenario C: Embedding native UI components into the Flutter widget tree.
    • Action: Use Platform Views (AndroidView / AndroidViewSurface for Android, UiKitView for iOS).
  • Scenario D: Web integration and JavaScript APIs.
    • Action: Use package:web and dart:js_interop (Wasm-compatible). Use HtmlElementView for embedding web content.