Flutter inside a live native app: engine groups, channels, and knowing when to stop
What I learned running Flutter as a guest inside production iOS and Android apps for fifteen months, and why we eventually turned the module into the app.
In July 2024 I shipped the first piece of Flutter into Third Wave Coffee’s ordering app: a bottom sheet, inside a native iOS app written in Swift and a native Android app written in Kotlin. For the next fifteen months, Flutter lived as a guest in those apps, taking over one feature at a time. In October 2025 I turned the Flutter module into the app itself.
This is what I would tell someone starting the same migration.
Why not rewrite
Both native apps had years of features and took orders every day. A rewrite meant freezing features for months, or building everything three times while the new app caught up. Add-to-app avoided both: the Flutter module compiles into the existing apps (an AAR on Android, CocoaPods on iOS), and native screens host Flutter views wherever we choose.
Start with something small and self-contained
The first surface was a bottom sheet: a few inputs, a few outputs, and nothing else depended on it. A safe place to learn the plumbing (build integration, engine start-up, channels, releases) without risking checkout. The next surfaces were harder because they lived inside native screens: product suggestions in a cart cell, a promo-balance card, the delivery widget on the home screen.
One engine per visible surface
A FlutterEngine drives one view at a time, so two Flutter surfaces on screen together need two engines. Plain engines are expensive; engines spawned from a FlutterEngineGroup share the GPU context, font metrics and isolate group snapshot, which makes each extra one cheap. Each starts at its own route.
On iOS:
let flutterEngines = FlutterEngineGroup(name: "app", project: nil)
func makeEngine(route: String) -> FlutterEngine {
let engine = flutterEngines.makeEngine(withEntrypoint: nil, libraryURI: nil, initialRoute: route)
GeneratedPluginRegistrant.register(with: engine)
return engine
}
On Android, one group is shared app-wide and each feature caches its engine so a fragment can pick it up later:
val engine = engineGroup.createAndRunEngine(
FlutterEngineGroup.Options(context)
.setDartEntrypoint(DartExecutor.DartEntrypoint.createDefault())
.setInitialRoute("/promo-balance"),
)
FlutterEngineCache.getInstance().put("promo_balance", engine)
// later, inside a native screen
val fragment = FlutterFragment.withCachedEngine("promo_balance").build<FlutterFragment>()
And on the Dart side, a single main() dispatches on the route the engine was started with:
void main() {
final route = PlatformDispatcher.instance.defaultRouteName;
runApp(SurfaceApp(route: route)); // '/promo-balance', '/delivery', ...
}
Pre-warm what lives in lists
A cold engine takes a moment to draw its first frame, and inside a native table cell that moment is a blank cell. On iOS we started five engines at launch for the surfaces inside native screens, and created the rest on first use. A discount-success dialog shown once per order does not need a warm engine; the cart suggestions do.
Every engine is its own world
This was the surprise that shaped everything else. Each engine runs main() in its own isolate, so your dependency-injection container, your singletons and your in-memory caches exist once per engine. Two Flutter surfaces on the same screen share no Dart state at all.
So the rule became: native owns anything shared. Login, the session, the selected store and the cart stayed native. When a Flutter surface starts, it asks native for the request headers it needs over a channel and stores them locally, instead of running a second auth flow that could drift from the first. When a Flutter surface adds something to the cart, it tells native, and native updates the cart.
Treat channels like an API
We ended with 13 method channels, one per surface. What kept them manageable:
- Names in one place. Every channel name and method name is a constant, defined once on each side, never typed inline.
- One channel per surface, so a surface can be removed without touching the others.
- Log what you do not recognise. A misspelled method name otherwise fails silently.
- Both directions are normal. Native tells Flutter to refresh, or to change opacity as the user scrolls. Flutter tells native it has no data, so native can collapse the cell, and asks native to dismiss a sheet, because native owns navigation.
abstract final class PromoBalanceChannel {
static const _channel = MethodChannel('com.example.app/promo_balance');
static void listen(PromoBalanceBloc bloc) {
_channel.setMethodCallHandler((call) async {
switch (call.method) {
case 'refresh':
bloc.add(const PromoBalanceRequested());
default:
log.warning('promo_balance: unhandled ${call.method}');
}
});
}
static Future<void> reportEmpty(bool isEmpty) =>
_channel.invokeMethod('dataEmpty', {'isEmpty': isEmpty});
}
Debugging across two worlds
The hardest bugs crossed the boundary: they started in Swift or Kotlin and surfaced in Dart, or the other way round, with a debugger, a log and a stack trace on each side. To step through Dart running inside the native app, you start the host from Xcode or Android Studio and connect with flutter attach. Hot reload works there; every native change still means a full rebuild.
Two habits paid for themselves. Logging every channel call a handler did not recognise, because a drifted name otherwise fails in silence. And reproducing bugs in the real host app, never a standalone Flutter run, because many only appear when both sides are running.
Knowing when to stop
Add-to-app has a running cost. Every new surface needs bridge code in three languages, every piece of shared state round-trips through native, and every release has to line up the module version with two host apps.
That cost is worth paying while Flutter owns a few features, and not once it owns most of them. In October 2025 I converted the module into a standalone Flutter app with its own Android and iOS runners, and the bridge code went away. The same codebase now builds the mobile website too.
If I did it again
- Decide the exit criteria up front. “When Flutter owns X, we flip” would have saved bridge code we later deleted.
- Keep shared state on the native side until the flip. With one isolate per engine, there is no single place in Dart for it to live.
- Budget for debugging. Two toolchains on every bug is a real cost; count it when you plan the migration.