Home / Insights / Mobile App Development
Mobile App Development
Flutter and Native Integrations: Platform Channels, Plugins and When to Write Native Code
Flutter covers most of what a mobile app needs from one Dart codebase, but sooner or later a feature needs the operating system directly. This guide explains the integration options, how to choose between them, and how to keep native code from becoming a maintenance trap.
Key takeaways
- Use a well-maintained existing plugin first; write native code only when no plugin fits, the plugin is abandoned, or you need control over behaviour and performance.
- Platform channels are asynchronous and untyped; for anything beyond a few calls, generate type-safe contracts with Pigeon.
- Use dart:ffi for C or C++ libraries and performance-sensitive synchronous calls, and platform views when you must embed a native UI component.
- Respect threading rules: channel handlers run on the platform main thread by default, so move heavy work to background task queues.
- Package native code as an internal plugin with its own example app, tests and owner, so it can be upgraded with Flutter and the operating systems.
On this page
- When does a Flutter app need native code?
- Which integration mechanism fits which job?
- How do platform channels work in practice?
- Why use Pigeon for type-safe contracts?
- Should native code live in the app or in a plugin?
- When should you use dart:ffi or platform views?
- How do you evaluate plugins and keep native code maintainable?
- Frequently asked questions
- Sources and methodology
One of the reasons teams choose Flutter is to write most of an app once, in Dart, for iOS and Android. That promise holds for the user interface and most business logic. It stops at the edge of the operating system: Bluetooth peripherals, health data, payment terminals, background location, vendor SDKs that only ship as Swift or Kotlin libraries, or a C++ image-processing library your scientists already trust.
This article is for CTOs, mobile leads and product owners who are planning a Flutter app with native requirements, or who have inherited one where native code has grown without a plan. I write from an architect’s perspective: which mechanism to use for which job, what it costs to maintain, and how to keep the native layer small and testable. Native integrations through platform channels are a standard part of our Flutter development work, alongside cross-platform UI, Flutter web and migration of older apps.
When does a Flutter app need native code?
Flutter renders its own UI and runs Dart code, so anything that depends on platform APIs has to cross a boundary. In practice, native work comes from four sources:
- Platform capabilities not covered, or not covered well, by existing packages: specialised Bluetooth profiles, NFC modes, background processing, health platforms such as Android’s Health Connect or Apple HealthKit, and new OS features in their first months.
- Vendor SDKs for payments, identity verification, telematics, mapping or analytics that are published only for iOS and Android.
- Existing native or C/C++ code you want to reuse rather than rewrite, such as signal processing, cryptography or computer vision.
- Native UI components that have no Flutter equivalent, such as a vendor’s camera view or a map SDK view.
Before committing to native code, check three things: whether a maintained package already does the job, whether the requirement is truly needed in the first release, and whether both platforms offer the capability at all. Some features exist on only one platform, and that is a product decision, not an engineering one.
Action: list every feature that touches hardware, OS services or third-party SDKs, and mark each one as covered by a package, needs a wrapper, or platform-specific.
Which integration mechanism fits which job?
Flutter offers several ways to reach native code. They are not interchangeable; each fits a different shape of problem.
| Mechanism | What it does | Best for | Trade-offs |
|---|---|---|---|
| Existing plugin package | Dart API backed by native code someone else maintains | Common capabilities: camera, location, storage, notifications | Quality varies; you inherit its bugs and release schedule |
| Platform channels (MethodChannel, EventChannel) | Asynchronous messages between Dart and Kotlin/Java or Swift/Objective-C | A few calls to platform APIs or a vendor SDK | Not type-safe; method names and argument types must match by hand |
| Pigeon-generated channels | Code generator producing type-safe channel code on both sides | Larger or long-lived native APIs | Adds a build step; generated code must be regenerated on change |
| dart:ffi | Direct calls from Dart into C APIs | C/C++ libraries, performance-sensitive or synchronous calls | Manual memory management; binaries per architecture |
| Platform views | Embeds a native view inside the Flutter widget tree | Native UI components such as maps, web views, vendor camera views | Performance and composition costs; test carefully on older devices |
Most production apps end up using more than one. A typical pattern is existing plugins for common capabilities, Pigeon for a wrapped vendor SDK, and occasionally FFI for a shared C++ library.
Action: for each item marked “needs a wrapper” in the previous step, choose a mechanism from this table and record why.
How do platform channels work in practice?
Flutter’s platform channels documentation describes the model: Dart sends a named method call over a channel, the host side handles it and replies with exactly one of success, error or “not implemented”. Messages are asynchronous and encoded with a codec, by default the StandardMessageCodec, which supports null, booleans, numbers, strings, byte and typed arrays, lists and maps.
Design rules we follow
- Keep the channel surface small. Expose a few coarse operations (“startScan”, “connect”, “readMeasurement”) rather than mirroring a native SDK method by method.
- Use unique, prefixed channel names such as a reverse-domain prefix, as the documentation recommends, to avoid collisions with plugins.
- Map errors deliberately. Convert native exceptions into a small set of error codes with messages, and catch
PlatformExceptionin Dart. “Bluetooth off”, “permission denied” and “device not found” deserve different handling in the UI. - Use event channels for streams such as sensor readings or connection state, rather than polling with method calls.
- Handle unavailable features. Simulators and some devices lack hardware; return a clear “unavailable” result rather than crashing.
Threading
Threading causes many hard-to-reproduce bugs. According to the documentation, host-side channel handlers run on the platform’s main thread by default, and calls from the host to Dart must also be made on the main thread. Heavy work on the main thread freezes the UI. Flutter supports background task queues for channel handlers on both Android and iOS, so long-running native work can run off the main thread, and you post results back to the main thread when needed. Background isolates can also use platform channels once registered with BackgroundIsolateBinaryMessenger.
Action: for every native handler, write down which thread it runs on and how long it can take. Anything that may block for more than a few milliseconds belongs on a background queue.
Why use Pigeon for type-safe contracts?
Plain method channels rely on string method names and loosely typed maps. That is manageable for two or three calls and fragile for twenty. A renamed argument on one side compiles fine and fails at runtime.
Pigeon, published by the Flutter team, solves this by generating channel code from a single Dart definition. You declare data classes and interfaces once; Pigeon generates matching code for Dart and for the host languages, including Kotlin, Java, Swift, Objective-C and C++. Host APIs (implemented natively, called from Dart) and Flutter APIs (implemented in Dart, called from native code) are both supported, and asynchronous methods can be generated. The platform channels documentation itself points to Pigeon for type-safe communication.
How we structure a Pigeon-based integration
- Write the contract file in Dart: data classes for requests and results, and an interface per capability.
- Generate code into the Dart package and the Android and iOS projects as part of the build or a documented script.
- Implement the generated host interfaces in Kotlin and Swift as thin adapters over the vendor SDK or platform API.
- Keep business logic in Dart, where it is shared and testable; native code only translates.
- Commit generated files, review contract changes like API changes, and regenerate whenever the contract changes.
For example, a field-inspection app integrating a laser measurement device might expose just three operations through Pigeon: list nearby devices, connect, and stream measurements. The vendor’s much larger SDK stays hidden behind those adapters. That is an illustrative pattern, but it is the shape we aim for.
Action: if your app has more than a handful of method channel calls, plan a migration to Pigeon in your next maintenance cycle.
Should native code live in the app or in a plugin?
Native code written directly inside the app’s android and ios folders works, but it tends to sprawl and is hard to test in isolation. Moving it into a plugin package, even a private one, gives it a boundary.
Flutter’s guide to developing packages and plugins distinguishes Dart packages, plugin packages (a Dart API with platform-specific implementations connected through a platform channel) and FFI plugins. It also describes federated plugins, which split a plugin into an app-facing package, a platform interface package and separate platform implementations. Federation lets different teams or vendors maintain each platform and makes it possible to add, say, web or desktop support later without touching the mobile implementations.
| Approach | Choose it when | Cost |
|---|---|---|
| Code inside the app project | One small integration, unlikely to be reused | Lowest setup; harder to test and upgrade cleanly |
| Private plugin in a monorepo | Several integrations, or reuse across your own apps | Moderate; needs an example app and tests |
| Federated plugin | Multiple platforms with different owners, or a public package | Highest; most structure and release coordination |
Whichever you choose, give the plugin an example app. It becomes the fastest way to reproduce native bugs without the rest of your product, and it is where we run platform-specific tests.
Action: move any native integration larger than a few hundred lines into a private plugin with its own example app and owner.
When should you use dart:ffi or platform views?
dart:ffi for C and C++
If the code you need is a C or C++ library, platform channels add an unnecessary hop through Kotlin or Swift. Flutter’s guide to binding to native C code using dart:ffi shows how to load a dynamic library and call its functions directly from Dart, with bindings generated by ffigen. On Android, libraries are shipped as .so files per architecture and built with CMake or ndk-build; closed-source libraries can be added as dependencies rather than bundled as binaries in the package.
FFI calls are synchronous. That is an advantage for small, fast functions, and a risk for slow ones: a long native call blocks the isolate that made it. Run heavy native work in a separate isolate. You also take on manual memory management across the boundary, so allocation and freeing rules need to be explicit and reviewed.
Platform views for native UI
When the native piece is a view, such as a map, web view or vendor camera preview, platform views let you embed it in the widget tree. They are powerful but have performance and composition costs that vary by platform and Android version. Prototype early on the oldest devices you support, and prefer a pure Flutter widget when one is good enough.
Action: for any FFI integration, document memory ownership for each function and add a stress test that calls it repeatedly to catch leaks.
How do you evaluate plugins and keep native code maintainable?
Most native risk enters through third-party plugins, not code you write. A plugin with poor maintenance can block a Flutter upgrade or an OS target-version update.
Plugin evaluation checklist
- Publisher identity and whether the package is verified or widely used.
- Recent releases and responsiveness to issues, especially after major iOS and Android releases.
- Support for the platforms and minimum OS versions you need.
- Licence compatible with your product.
- Permissions and privacy declarations it adds to your app.
- Whether the native code is small enough for your team to fork and maintain if needed.
Keeping native code healthy
- Name an owner for each native integration who can read Kotlin and Swift.
- Test at three levels: Dart unit tests with a mocked channel, native unit tests for adapters, and integration tests on real devices. Our guide to mobile end-to-end testing tools covers the device layer.
- Upgrade on a schedule. Review plugins and native SDK versions each quarter and after major OS releases.
- Track app size. Native SDKs and FFI libraries add weight; watch download size per release.
- Handle permissions consistently across platforms, with clear explanations to users. Health and fitness data is a good example; see our article on integrating Health Connect on Android.
On the Care Management Platform we built with Flutter and Firebase for Australian disability and aged care providers, the principle that served us best was to keep business logic in Dart and treat native code as thin, well-tested adapters. It keeps most of the team productive in one language while still allowing platform-specific behaviour where it matters.
Action: run the plugin checklist against your current dependencies and replace or fork any plugin that fails more than two items.
Frequently asked questions
Does needing native code mean Flutter was the wrong choice?
Not usually. Most Flutter apps need some native code, and the platform is designed for it. Flutter becomes a poor fit when most of the app is platform-specific UI or heavy native SDK work, leaving little shared code.
Do we need separate iOS and Android developers?
For apps with significant native integrations, you need people who can read and write Kotlin and Swift, even if most work is in Dart. A small team often has one or two engineers who cover the native layer for both platforms.
How long does it take to wrap a vendor SDK?
It depends on the SDK’s size, quality and how much of it you expose. A thin wrapper around a few operations can be a short task; a large SDK with callbacks, background behaviour and UI components needs more design and device testing. Expose only what the product needs.
Is Pigeon production-ready?
Pigeon is published by the Flutter team and recommended in the official platform channels documentation for type-safe communication. As with any code generator, pin its version, commit generated code and review changes to the contract.
When should we use dart:ffi instead of platform channels?
Use FFI when the native code is a C or C++ library or when you need fast synchronous calls. Use platform channels or Pigeon when you are calling Kotlin, Java, Swift or Objective-C APIs, including most vendor SDKs.
Sources and methodology
Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.
- Flutter documentation: Writing custom platform-specific code (platform channels) — accessed 9 November 2026. Channel types, StandardMessageCodec types, reply rules, naming, error handling, main-thread rules and background task queues.
- pub.dev: pigeon package (flutter.dev) — accessed 9 November 2026. Type-safe code generation for Flutter and host platforms, supported languages, host and Flutter APIs and async methods.
- Flutter documentation: Developing packages and plugins — accessed 9 November 2026. Package types, plugin packages, FFI plugins and the federated plugin structure.
- Flutter documentation: Binding to native Android code using dart:ffi — accessed 9 November 2026. Loading dynamic libraries, ffigen bindings, per-architecture .so files and packaging approaches for native libraries.
Related reading
Continue your research
Is native code making your Flutter app harder to maintain?
We can review your plugins and native integrations and propose a cleaner, testable structure.
