# Flutter Native

> Build type-safe native platform integrations using MethodChannels, EventChannels, and Pigeon. Use when communicating with Android/iOS native code, implementing federated plugins, or bridging platform-specific APIs. Use when this capability is needed.

- Skill: `tomevault-io/flutter-native` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/flutter-native`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/flutter-native/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/flutter-native

---


# Native Platform Interoperability

Developing Flutter apps often requires direct communication with the underlying native platform (Android/iOS). This skill covers the standards for maintainable and type-safe interoperability.

## 1. MethodChannels (One-shot)

Use `MethodChannel` for standard request-response patterns between Dart and Native.

### Dart Standard
- Use a unique domain-style channel name.
- ALWAYS wrap calls in a try-catch for `PlatformException`.

```dart
static const _channel = MethodChannel('com.example.app/device_info');

Future<String?> getDeviceOS() async {
  try {
    return await _channel.invokeMethod<String>('getOS');
  } on PlatformException catch (e) {
    AppLogger.error('Failed to get OS', error: e);
    return null;
  }
}
```

## 2. EventChannels (Streams)

Use `EventChannel` for continuous data flow (e.g., sensor data, connectivity).

### Implementation
- Native side MUST handle `onListen` and `onCancel`.
- Dart side MUST dispose the subscription to prevent leaks.

## 3. Type Safety with Pigeon

For complex APIs, avoid manual string-based keys. Use **Pigeon** to generate type-safe interfaces.

## 4. Platform-Specific Directory Structure

Organize native code within the relevant feature if possible, or use a dedicated `plugins/` directory for shared logic.

## 5. Federated Plugins

If the logic is reusable across multiple apps:
- Split implementation into `_platform_interface`, `_android`, `_ios`, and `_web` packages.
- Provide a single entry point for users.

---
> Source: [dhruvanbhalara/skills](https://github.com/dhruvanbhalara/skills) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-22 -->

