When Pure Cross-Platform Hits a Wall
Flutter is my default choice for 80% of mobile product development, but last-mile delivery navigation in Istanbul is an extreme edge case. Couriers mount mid-range Android devices on sunlit dashboards in dense traffic, relying on sub-second GPS bearing updates, toll-road warnings, and manoeuvre callouts.
Pumping high-frequency location telemetry, polyline snapping, and camera tilt animations across a platform channel into a Flutter map wrapper introduced noticeable frame jitter during rapid re-routing. For D2D, we needed native Android performance where milliseconds matter, without giving up Flutter’s velocity for the rest of the courier workflow.
Drawing the Native vs. Flutter Boundary
Instead of forcing the entire app into one paradigm, we drew a clean architectural seam around the active driving session:
1. **Flutter Layer (Dispatch & Operations):** Handles shift check-in, package manifest lists, customer contact actions, and proof-of-delivery capture. These screens benefit enormously from declarative UI and shared business logic.
2. **Native Kotlin Layer (Route Selection & Live HUD):** Owns the Google Maps SDK instance, multi-route comparison overlay (ranking the top 3 routes by ETA and distance), live speed readout, and turn-by-turn audio/visual callouts.
class NavigationSessionController(
private val mapController: GoogleMapController,
private val telemetryChannel: EventChannel.EventSink?
) {
fun onLocationTick(fix: LocationFix, activeRoute: RouteGeometry) {
// 1. Update camera bearing & speed HUD directly on the native UI thread
val snapped = RouteSnapper.snapToPolyline(fix, activeRoute)
mapController.animateBearingAndTilt(snapped.latLng, fix.bearing, fix.speedKmh)
// 2. Only emit coarse state transitions to Flutter (e.g. arrived at stop)
if (snapped.distanceToDestinationMeters < 35.0) {
telemetryChannel?.success(mapOf("event" to "ARRIVING_AT_STOP"))
}
}
}Do not stream 10 Hz GPS coordinates over a Flutter Platform Channel just to update a UI label. Keep high-frequency sensor loops on the side of the bridge that renders the pixels, and only cross the boundary on coarse state transitions.
Ranking 3 Viable Routes in Under 2 Seconds
Before a driver pulls away from the depot, D2D fetches and renders up to three viable routes simultaneously on the map—for example, a 33-minute / 28.7 km highway route versus a 35-minute / 27.3 km toll-free alternative.
By parallelizing route decoding and bounding-box calculation in Kotlin Coroutines (`Dispatchers.Default`) before handing pre-built polyline overlays to the map view, route comparison loads in under 2 seconds even on budget courier handsets—reducing wrong-turn incidents by an estimated 30%.