Most of the Flutter work we are asked to quote in 2026 is not a greenfield app. It is a company with a shipping native iOS and Android app, a roadmap they cannot pause, and one or two screens they are tired of building twice. They want to know whether Flutter can go inside the app they already have, one feature at a time, without a rewrite and without wrecking startup time.
The answer is yes — Flutter's add-to-app support is mature — but the defaults will embarrass you. A naively embedded Flutter screen costs ~1.5s on first open, leaks an engine per route, and loses its state every time the user backs out. This tutorial covers the version that survives a production review: pre-warmed engines, engine groups, a typed bridge, memory discipline, build integration for both platforms, and the tests and metrics that prove it is safe.
When add-to-app is the right call
Add-to-app is a good fit when:
- One product surface (onboarding, checkout, a loyalty hub, a rewards wallet) is being built twice by two teams and drifting.
- You need to prove Flutter internally before anyone signs off on a rewrite.
- The native app has deep platform integration — widgets, CarPlay, Wear, SDKs — that you are not willing to port.
It is the wrong call when more than roughly 60–70% of the app is destined for Flutter anyway. Past that point you pay the hybrid tax (two build systems, two dependency graphs, a bridge) for a transition state you will exit in six months. Full migration, screen by screen, behind a native shell, is cheaper.
Be honest about the costs up front, because they are real:
| Cost | Impact |
|---|---|
| App size | +4–6 MB per platform after the engine and ICU data land |
| Build time | Flutter module build added to both CI pipelines |
| Memory | ~20–40 MB resident per live Flutter engine |
| Debug workflow | Hot reload needs flutter attach, not the native debugger |
Project layout
Create the Flutter module beside the two native projects, not inside either of them:
company-app/
ios/ # existing Xcode project
android/ # existing Gradle project
flutter_module/ # created below
flutter create --template module --org com.company flutter_module
The module produces an .xcframework/CocoaPods or SPM artifact for iOS and an AAR or Gradle subproject for Android. Pin the Flutter SDK version in the repo (.fvmrc or flutter --version captured in CI) — a native team member on a different Flutter channel is the most common broken build in hybrid projects.
Android integration
In settings.gradle.kts of the host app:
include(":app")
val filePath = settingsDir.parentFile.toPath()
.resolve("flutter_module")
.resolve(".android")
.resolve("include_flutter.groovy")
apply(from = filePath)
// app/build.gradle.kts
dependencies {
implementation(project(":flutter"))
}
Source integration like this gives the Flutter team hot reload inside the host app. If your native CI must not have the Flutter SDK installed, publish an AAR instead (flutter build aar) to an internal Maven repo and depend on a version number. Most teams we work with run source integration locally and AAR in CI.
Pre-warming the engine
The default FlutterActivity boots an engine when the screen opens. That is the 1.5s. Pre-warm instead:
class App : Application() {
lateinit var flutterEngine: FlutterEngine
private set
override fun onCreate() {
super.onCreate()
flutterEngine = FlutterEngine(this).apply {
dartExecutor.executeDartEntrypoint(
DartExecutor.DartEntrypoint.createDefault()
)
}
FlutterEngineCache.getInstance().put(ENGINE_ID, flutterEngine)
}
companion object { const val ENGINE_ID = "primary" }
}
startActivity(
FlutterActivity.withCachedEngine(App.ENGINE_ID)
.backgroundMode(FlutterActivity.BackgroundMode.opaque)
.build(context)
)
Do not pre-warm in Application.onCreate() unconditionally if your cold start budget is tight — you have just moved the cost onto every launch, including launches that never reach Flutter. Two better patterns:
- Lazy pre-warm on intent. Warm the engine when the user lands on the tab or screen that links into Flutter, not at app launch.
- Deferred pre-warm. Warm after first frame of the native home screen, on a background idle callback.
Measure both against your cold start dashboard before you choose. We have seen a 180ms regression in app launch traded for a 1.3s win on the Flutter route — usually worth it, but it must be a decision, not an accident.
Multiple screens: FlutterEngineGroup
One cached engine works until you need two Flutter screens alive at once (a tab plus a pushed detail). A second standalone engine costs the full ~20–40 MB. FlutterEngineGroup spawns engines that share the snapshot, GPU context, and most of the resident memory — typically ~180 KB each after the first.
val engineGroup = FlutterEngineGroup(context)
val checkoutEngine = engineGroup.createAndRunEngine(
context,
DartExecutor.DartEntrypoint(
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
"checkoutMain",
),
)
Each engine runs an isolate with its own memory; they do not share Dart state. Anything both screens need — auth token, cart — belongs behind the bridge in native code or a shared backend, not in a Dart global.
iOS integration
With CocoaPods, in the host Podfile:
flutter_application_path = '../flutter_module'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
target 'HostApp' do
install_all_flutter_pods(flutter_application_path)
end
post_install do |installer|
flutter_post_install(installer) if defined?(flutter_post_install)
end
Flutter's iOS tooling now supports Swift Package Manager, and if your host app has already left CocoaPods you can add the module's generated package instead of reintroducing a Podfile. Check flutter config --list for the SPM flag on your SDK version and confirm every plugin you depend on ships a Package.swift — a single Pod-only plugin forces the whole target back to CocoaPods.
Pre-warm with FlutterEngine held by the app delegate:
@main
class AppDelegate: FlutterAppDelegate {
lazy var flutterEngine = FlutterEngine(name: "primary")
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
flutterEngine.run()
GeneratedPluginRegistrant.register(with: flutterEngine)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
let vc = FlutterViewController(engine: appDelegate.flutterEngine, nibName: nil, bundle: nil)
vc.modalPresentationStyle = .fullScreen
navigationController?.pushViewController(vc, animated: true)
Subclassing FlutterAppDelegate is the shortcut; if you cannot (many enterprise apps have an app delegate owned by another team), forward the lifecycle calls to FlutterPluginAppLifeCycleDelegate manually or plugins that rely on lifecycle callbacks — push, deep links, biometrics — will silently misbehave.
The iOS equivalent of engine groups is FlutterEngineGroup(name:project:), with the same rule: shared resources, separate isolates.
The bridge: type it, version it, test it
Hand-written MethodChannel code is where hybrid apps rot. Strings on both sides, no compile-time check, and a crash in production when someone renames an argument. Use Pigeon to generate the interface from a Dart definition.
// pigeons/host_api.dart
import 'package:pigeon/pigeon.dart';
@ConfigurePigeon(PigeonOptions(
dartOut: 'lib/src/generated/host_api.g.dart',
kotlinOut: 'android/app/src/main/kotlin/com/company/HostApi.g.kt',
swiftOut: 'ios/Runner/HostApi.g.swift',
))
class Session {
Session({required this.accessToken, required this.userId, this.email});
final String accessToken;
final String userId;
final String? email;
}
@HostApi()
abstract class HostSessionApi {
@async
Session currentSession();
void close({required String reason});
void logEvent(String name, Map<String, String> params);
}
@FlutterApi()
abstract class FlutterRouteApi {
void openRoute(String route, Map<String, String>? args);
}
dart run pigeon --input pigeons/host_api.dart
Now the Kotlin and Swift sides implement a generated protocol, and renaming a field breaks the native build instead of the user's checkout.
Three rules that have saved us every time:
- The host owns auth. Flutter asks for a token; it never stores credentials or refreshes them. One refresh implementation, in native code, no race between two token stores.
- Every Flutter screen can close itself.
close(reason:)is not optional. Without it, a Flutter error state becomes a trap with no back button on iOS modals. - Version the contract. Add an
apiVersionfield returned by the host. When an OTA-updated Flutter module meets an older host binary, you want a clean fallback, not aMissingPluginException.
Navigation that does not fight the host
Two reasonable models:
Screen-at-a-time (recommended to start). Each Flutter route is pushed by the native navigator; Flutter runs a single page with no internal navigator. Back gestures, native transitions, and analytics screen tracking all keep working.
Flutter-owned flow. Flutter runs its own Navigator/go_router for a multi-step flow (onboarding, checkout) and hands control back only at the end. Use PopScope so the Android back button pops the Flutter stack first and only exits the activity when the Flutter stack is empty:
PopScope(
canPop: !Navigator.of(context).canPop(),
onPopInvokedWithResult: (didPop, _) {
if (!didPop) return;
HostSessionApi().close(reason: 'user_back');
},
child: child,
);
For deep links, let the host resolve the URL and call FlutterRouteApi.openRoute(). If both the host and go_router try to parse incoming links you get double navigation on cold start — the single most reported hybrid bug in our engagements.
Memory and lifecycle discipline
- Detach, do not destroy, on pop when the screen will be reopened. Keeping the cached engine alive preserves state and makes reopen instant.
- Destroy the engine (
engine.destroy()/ release the Swift reference) when the user logs out or leaves a one-off flow. Also clear the Dart-side caches first; an image cache in a retained engine is invisible to native memory tooling and gets blamed on the host app. - Trim on background. Respond to
onTrimMemory/didReceiveMemoryWarningby calling into Dart to evictPaintingBinding.instance.imageCache. - Watch the platform view count.
WebView, maps, and camera previews inside an embedded Flutter view are hybrid composition surfaces inside an already-composited view. Two is usually fine; a scrolling list of them is not.
Build, CI, and release
- Build the module as an artifact (AAR, xcframework) in a Flutter-owned pipeline; version it semantically; publish to an internal repository. Native CI then needs no Flutter SDK.
- Keep a
flutter_moduleversion pin in both host repos and bump it with a PR — that PR is your audit trail for "which Flutter version is in production". - Run
flutter build aar --analyze-sizeand track the delta per release. Hybrid apps gain size quietly. - Symbolicate both worlds. Upload Dart
--split-debug-infosymbols alongside your native dSYMs/mapping files or every Flutter crash arrives as hex. - Integration tests: drive the host app with Maestro or XCUITest/Espresso through the native entry point into the Flutter screen, and keep widget tests inside the module. Patrol works well when the Flutter surface owns most of the flow.
A realistic rollout
A plan we have run more than once, and the one we would propose on a first engagement:
- Week 1–2. Module scaffold, both hosts building in CI, one trivial Flutter screen behind an internal-only flag. Prove the build, not the feature.
- Week 3–4. Pigeon bridge for session, analytics, and close. Pre-warm strategy chosen against measured cold start.
- Week 5–8. First real feature, shipped to 5% behind the existing remote config flag, with crash rate, ANR rate, cold start, and memory compared against the control group.
- Then decide. Either the numbers justify more surfaces, or you roll back by flipping a flag and have lost one sprint instead of a year.
That last point is the real argument for add-to-app: it is the only Flutter adoption path with a cheap exit.
AviaryApps supplies senior Flutter consultants who have taken hybrid apps from first embedded screen to production rollout. If you have a native app and one feature you are tired of building twice, get in touch — or if you are a Flutter developer looking for your next contract, see our careers page.