Leaving Flutter one screen at a time.
Moving the Laayo customer app from Flutter to Swift and Kotlin without a rewrite: native screens inside Flutter, swappable data layers, then the shell.
The Laayo customer app started as a Flutter app. It is now Swift on iOS and Kotlin on Android. There was no day when I stopped shipping to rewrite it. Screens moved one at a time inside the running Flutter app, and the Flutter engine came out last.
Native screens inside a Flutter app
The first native screens were opened from Dart. A Flutter route handed over to a native view controller or activity through a method channel, passed the arguments it needed, and got a result back when the screen closed. To the rest of the app, a native screen was just another route.
At that stage Dart still owned the state: session, cart, zone, selected address. Native screens read it and did not write it. That one rule kept the two halves from disagreeing about what was in the cart. When a native screen needed to change something, it asked Dart to do it over the channel.
Each module got a repository interface with two implementations:
- a Dart-backed repository that asks Flutter for the data over a channel, used first
- an API-backed repository that calls the server directly, used later
The screen doesn't know which one it has. A server config value per module chooses, plus one "everything back to Dart" option that exists only as a rollback. That let me move a module's data to native, watch it, and move it back without shipping a build. Once the shell itself went native, the switch stopped mattering, which is the right way for a migration switch to end.
Native screens copied the existing Flutter design exactly: same layout, same copy, same states. Redesigns were separate decisions. A migration that also changes how things look makes every bug report ambiguous.
Two native codebases, not one shared one
I looked at Kotlin Multiplatform for a shared data layer and decided against it. Android was going to be Kotlin anyway, so I kept two plain native codebases with the same contract. The cost is that every behaviour is written twice. Each feature has a written spec that both platforms build to, and strings live in English and Nepali files with identical keys on both sides.
Bugs that live at the boundary
Two bugs from the hybrid period are worth knowing about if you do the same thing.
On iOS, Flutter plugins present their UI from the root Flutter view controller. With a native screen already presented on top, the image picker's present call was silently ignored by UIKit. The camera kept working, because it uses its own window, which made it harder to spot. The fix was a small FlutterViewController subclass that forwards present to the top-most view controller.
Also on iOS: a native chat screen presented over the native tracking screen vanished when the tracking screen was closed, because dismissing a view controller also dismisses whatever it is presenting. The rule since then: never present a native screen on top of another native screen that is about to close. Close first, then present.
Removing the engine without logging anyone out
Before taking Flutter out, I made an inventory of everything Dart still did: every route (most were native by then, a handful were Flutter only, a few were dead), push handling, deep links, login and OTP, location, the voice assistant, crash reporting and stored data. Each item got a step. The order was: core data owners, API repositories for the heavy modules, the last screens, native login and session, push, the native shell behind a remote flag, the remaining services, and finally removing Flutter.
Stored data was the step that could hurt people. Flutter's shared_preferences plugin stores keys with a flutter. prefix: on Android in a file named FlutterSharedPreferences, on iOS in the standard user defaults. The native app reads those keys on first launch, so customers stay signed in and keep their saved address.
fun migrateFlutterPrefs(ctx: Context) {
val old = ctx.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE)
val new = ctx.getSharedPreferences("app", Context.MODE_PRIVATE)
if (new.getBoolean("migrated_from_flutter", false)) return
val edit = new.edit()
for (key in listOf("user_token", "guest_id", "user_address", "theme", "language")) {
old.getString("flutter.$key", null)?.let { edit.putString(key, it) }
}
edit.putBoolean("migrated_from_flutter", true).apply()
}fun migrateFlutterPrefs(ctx: Context) {
val old = ctx.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE)
val new = ctx.getSharedPreferences("app", Context.MODE_PRIVATE)
if (new.getBoolean("migrated_from_flutter", false)) return
val edit = new.edit()
for (key in listOf("user_token", "guest_id", "user_address", "theme", "language")) {
old.getString("flutter.$key", null)?.let { edit.putString(key, it) }
}
edit.putBoolean("migrated_from_flutter", true).apply()
}Two other consequences had to be planned for, not discovered:
- The customer website was Flutter web, in the same project. Before Flutter left the mobile project, I froze a copy of it to keep building and serving the website until the website is rebuilt.
- Over-the-air Dart patches end with Flutter. Every fix becomes a store release, so release builds and crash reporting had to be ready first. Crash reports are sent from release builds only, with no personal data and no screenshots.
Some things were dropped instead of ported. Social login is Google and Apple only in the native app, and an old checkout flow that was already switched off in production was not rebuilt at all.
Builds were the other constraint. I write most of the code on a Linux server and compile on a Mac. A big pile of Swift and Kotlin that has never been compiled is a risk of its own, so step zero of the plan was simply to compile everything written so far before adding anything more.
Get new posts by email
One email when something new goes up. No tracking pixels, unsubscribe in one click.