Flutter · One codebase, native feel

How do you integrate existing native code and SDKs?

Hardnative integrationffiplatform viewsadd-to-appUpdated Oct 2026
Quiz this track

Short answer

Choose channels for service calls, FFI for C and C++ libraries, platform views for native UI, and add-to-app when Flutter must live inside an existing native app.

The integration mechanism should follow the boundary. A native SDK with a simple request-response API fits a MethodChannel or Pigeon. A performance-sensitive C library fits dart:ffi. A map or camera preview that must be a real native view fits a platform view. Embedding Flutter in an existing app is a separate integration path with its own engine lifecycle.

dart
import 'dart:ffi';

typedef NativeAdd = Int32 Function(Int32 a, Int32 b);
typedef DartAdd = int Function(int a, int b);

final add = DynamicLibrary.open('libmath.so')
    .lookupFunction<NativeAdd, DartAdd>('add');

int sum(int a, int b) => add(a, b);
FFI calls are synchronous, so they must stay short or run on a helper isolate.
  • Channels are easiest for platform APIs and lifecycle callbacks
  • Pigeon reduces type and naming errors across Dart, Kotlin and Swift
  • FFI avoids channel serialisation but requires manual memory management with malloc and free
  • Platform views composite native UI and can be expensive to animate or nest
  • Add-to-app needs a stable engine cache and careful route and lifecycle handoff

Risk areas

Native SDKs may assume they own the application delegate or main activity lifecycle. Initialise them early and handle background and foreground transitions. Platform views can break screenshot tests and accessibility unless semantics are supplied. FFI mistakes can crash the process rather than throw a Dart exception, so bounds and pointer lifetimes need strict review.

Do not put business logic in native code just because the existing SDK is native. Keep the boundary small and map native errors into explicit Dart failures.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1When would you choose FFI over a MethodChannel?
  2. 2What are the costs of a platform view?
  3. 3How would you integrate a native SDK that needs app lifecycle callbacks?
  4. 4What changes when Flutter is embedded into an existing native app?

Say it in the interview

I pick the boundary based on the native capability. For service calls I use channels or Pigeon, for C or C++ libraries I use FFI, and for real native UI such as a map I use a platform view. Each has costs: FFI has manual memory safety, platform views have compositing cost, and add-to-app has engine lifecycle complexity. I keep the native boundary narrow and translate errors explicitly.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Flutter mock interview and get scored feedback on depth, clarity and confidence.