← ClaudeAtlas

kotlinlisted

Writing the Android-native (Kotlin) side of a Flutter app for features Flutter can't reach — a MethodChannel handler registry, main-looper dispatch, notImplemented defaults, and Native↔Flutter invocation. Auto-applies when editing any Kotlin file.
virajp/ai-plugins · ★ 1 · AI & Automation · score 78
Install: claude install-skill virajp/ai-plugins
# Android Native (Kotlin) via Platform Channels Use Kotlin only for capabilities Flutter/Dart can't express — Android Auto, app widgets, foreground services, deep OS integrations. Everything crosses the boundary through a `MethodChannel`; keep the native side a thin dispatcher and push logic back into Dart where you can. ## Channel dispatcher One channel per feature as an `object` (singleton). Prefer a **handler registry** keyed by method name so several screens can each register their own methods without overwriting a single monolithic `when` block: ```kotlin package app.carapp import android.os.Handler import android.os.Looper import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel /// Centralized dispatcher for the com.app/car_extension MethodChannel. object CarAppChannel { private const val CHANNEL_NAME = "com.app/car_extension" private val handlers = mutableMapOf<String, (MethodCall, MethodChannel.Result) -> Unit>() fun registerHandler(method: String, handler: (MethodCall, MethodChannel.Result) -> Unit) { handlers[method] = handler } fun unregisterHandler(method: String) = handlers.remove(method) } ``` - Channel name is a reverse-DNS string shared verbatim with the Dart side — `com.app/<feature>`. Define it once as a `const`. - Each screen calls `registerHandler` in its init and `unregisterHandler` in its cleanup/`onDestroy` — lifecycle owns the handler, not the channel. ## Initialization & Flutter → Native Bi