Sub topic 13
Limitations and Trade-offs to Plan For
This chapter assumes that you understand basic Flutter and Dart, can run a Flutter app with the flutter CLI, and have working knowledge of either Android with Kotlin and Gradle or iOS with Swift, Xcode, and CocoaPods.
Flutter add-to-app lets a native application adopt Flutter one screen or feature at a time. That reduces rewrite risk, but it also creates a hybrid application. You must manage two UI frameworks, two build systems, and a boundary between native and Dart code.
Where the Costs Appear
An embedded Flutter feature includes the Flutter engine, Dart runtime, compiled Dart code, assets, and plugins. A small Flutter screen can therefore increase the application size more than an equivalent native screen.
The engine also uses memory and needs time to start. Pre-warming an engine improves the first-screen launch time, but the cached engine consumes memory while it waits. Reusing one engine saves resources, while separate engines provide more isolation.
| Decision | Benefit | Cost or risk |
|---|---|---|
| One shared engine | Lower memory use and faster later launches | More shared state and lifecycle coordination |
| A separate engine per feature | Better isolation between features | Higher memory use and slower startup |
| Native-to-Flutter channel calls | Simple for small integrations | Manual contracts and runtime errors |
| Generated messaging with Pigeon | Typed interfaces and clearer contracts | Code-generation setup and version coordination |
| Gradual add-to-app migration | Smaller delivery risk | Hybrid navigation, testing, and build complexity |
Boundaries Between Native and Flutter
A platform channel is a runtime message path between Dart and native code. It works well for focused operations such as reading a user name, opening a native screen, or requesting a device capability.
The boundary becomes difficult when large objects, frequent updates, or many callbacks cross it. Messages must be serialized into supported values, and both sides must agree on method names and data shapes. A renamed method can fail only when a particular screen runs.
Keep the boundary narrow:
- Let each side own its local state.
- Send commands and small data objects rather than entire application state.
- Define behavior for missing data, errors, timeouts, and an unavailable native feature.
- Use Pigeon when the interface has several methods or shared data types.
- Test both sides with contract-focused tests.
Navigation is another boundary. A Flutter route is not automatically an Android Activity or an iOS view controller. Decide which system owns the back button, deep links, authentication transitions, and analytics events.
Lifecycle, State, and Multiple Engines
A Flutter engine has a Dart isolate, which is the execution context for Dart code. The isolate can retain state while a Flutter view is removed from the screen. This may be useful for a logged-in session, but it can surprise users who expect a new screen to start fresh.
A shared engine can also make independent Flutter features affect one another through global state, plugins, or route history. Destroying the engine too early loses that state. Keeping it forever increases memory use.
The following model shows the main trade-off:
Build, Release, and Upgrade Constraints
Android integration must remain compatible with the host project's Gradle, Android Gradle Plugin, Kotlin, and minimum SDK choices. iOS integration must remain compatible with the deployment target, Xcode, CocoaPods, and plugin requirements. The host application owns the final release build, so a Flutter plugin can force changes to native build settings.
Choose a packaging approach deliberately:
- A source-based module gives the most flexibility during development and keeps Flutter tooling close to the host project.
- An Android AAR or iOS framework can fit a controlled binary integration process, but it requires a repeatable build and distribution pipeline.
- Prebuilt artifacts can speed host builds, but every Flutter code or asset change requires publishing a new artifact.
Run release builds early. Debug behavior can hide missing assets, incorrect plugin registration, signing problems, or channel error handling.
> callout warning > Add-to-app reduces rewrite risk, but it does not remove ownership. Assign clear owners for Flutter code, native integration, channel contracts, release packaging, and dependency upgrades. >
When Add-to-App Is the Wrong Choice
A full Flutter application may be simpler when most screens share one design system and the team controls the whole product. Native development may be better when the feature depends heavily on platform-specific UI, accessibility behavior, or existing native navigation.
Choose add-to-app when gradual migration, shared Flutter code, or a self-contained Flutter feature outweighs the extra integration cost. Reassess the decision if every screen needs frequent cross-boundary communication.
Exercise
Why might a team choose a cached shared engine instead of creating a new engine for every Flutter screen?
Show answer
A cached engine can reduce startup latency and memory use, although the team must manage shared state and lifecycle carefully.