#MethodChannel
今日のZennトレンド

Flutter アプリを iPhone Duo の「縦帯」に対応させる
FlutterKaigi 2026のアプリをiPhone Duoの縦帯表示に対応させた内容です。
Xcode 27.1で発生するコンテンツの潜り込みに対し、SafeAreaによる判定でタブバーを縦帯内に配置し、レイアウトを最適化しました。
また、MethodChannelでネイティブ側からカメラ穴の位置情報を取得し、動的に余白を調整することで、UIの重なりを解消しています。
Flutter アプリを iPhone Duo の「縦帯」に対応させる
こんにちは、ゆうです。FlutterKaigi 2026のアプリの開発をしています。Xを見ると、iPhone Duoを買った人が思ったより多いようでした。mixi2さんがFlutterでiPhone Duoに最適化しているポストも流れてきたので、FlutterKaigi 2026のアプリも対応することにしました。https://x.com/chehonz201/status/21135784427
zenn.dev
October 25, 2026 at 1:31 PM
今日のQiitaトレンド

FlutterからFoundation Modelsを呼ぶ最小構成
FlutterからAppleのFoundation Models(オンデバイスモデル)を利用する最小構成の実装方法を解説しています。
MethodChannelを用いてSwift経由でAPIを呼び出す構成とし、AI処理をSwift側に集約させることで、Dart側にApple固有の複雑な設計を持ち込まない実装を提案しています。
iOS 26.0以降を前提とした構成です。
FlutterからFoundation Modelsを呼ぶ最小構成 #AI - Qiita
はじめに FlutterでiOSアプリを作っていると、Apple固有の新しいAPIを使いたい場面があります。 Foundation Modelsもその一つです。Apple Intelligenceを支えるオンデバイスモデルへ、SwiftのFoundationModelsフ...
qiita.com
September 27, 2026 at 12:29 AM
Choosing Between MethodChannel and PlatformView: A Real Decision, Not a Rule of Thumb
## I Embedded a Native Camera Preview in Flutter (And Learned Exactly Where MethodChannel Stops Being Enough) Seven years into mobile engineering, I wanted to answer a question I've seen a few times: when do you actually need PlatformView instead of MethodChannel? Most answers I've seen are either "PlatformView is for native UI" (true, but not useful) or skip straight to copy-pasteable boilerplate with none of the failure modes that actually teach you anything. Over the weekend, I built a small Flutter app that embeds a native Android camera preview with a live ML Kit face-detection overlay, drawn natively, not through a Flutter widget stacked on top. This article is the build and, more usefully, the three things that broke along the way and what each one taught me about how Flutter's native bridging actually works under the hood. ## Why MethodChannel wasn't the question Before touching code, it's worth being precise about something I initially framed loosely myself: `MethodChannel` isn't "too weak" for native work; it's just the wrong tool for a specific job. It's a request/response bridge. Dart calls a method, native code handles it, returns a result. For one-off calls, biometric auth, reading an NFC tag, taking a photo, it's genuinely the right tool, no asterisk needed. What it categorically cannot do is put a native `View` inside your Flutter widget tree. It moves data, not UI. The moment you need an actual native surface rendering live inside your layout- a camera preview, a map SDK's own view- you need `PlatformView`. That's not a performance tradeoff or a style preference. It's the only mechanism Flutter gives you for that job. So the real architecture question for LensBridge wasn't "MethodChannel or PlatformView". It was "PlatformView for the pixels, MethodChannel for the commands," running side by side, each doing what it's actually built for. ## The architecture * **`PlatformView`** hosts a `PreviewView` (CameraX) wrapped in a `FrameLayout`, with a second custom `View` stacked on top for drawing detection boxes * **`ImageAnalysis`** (a separate CameraX use case from `Preview`) feeds frames to ML Kit's on-device face detector * **`MethodChannel`** handles the three things Dart needs to _tell_ native code to do: switch lens, stop, start class CameraPlatformView( private val context: Context, viewId: Int, private val lifecycleOwner: LifecycleOwner ) : PlatformView { private val previewView: PreviewView = PreviewView(context).apply { implementationMode = PreviewView.ImplementationMode.COMPATIBLE } private val overlayView: OverlayView = OverlayView(context) private val container: FrameLayout = FrameLayout(context).apply { addView(previewView, FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)) addView(overlayView, FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)) } override fun getView(): View = container // ... } Two lines in there, `implementationMode` and the explicit `LayoutParams`, look unremarkable. They cost me two separate debugging sessions. More on both below. ## What actually broke ### 1. `unbindAll()` doesn't clear the surface After wiring MethodChannel controls for Stop, hitting it left the last camera frame frozen on screen instead of going blank. Not a bug. `PreviewView` is backed by a `SurfaceView`/`TextureView`, and `unbindAll()` stops new frames from being pushed but never explicitly clears the existing buffer. Nothing tells the GPU to draw anything else over it, so the last frame just sits there. Confirmed it was genuinely stopped (not stalled) by waving a hand in front of the camera. No update. Fixed it by explicitly toggling `previewView.visibility` on stop/start rather than relying on frame delivery to communicate state. ### 2. A completely silent 0×0 view Once ML Kit was wired up and logcat confirmed detection was running (`face_count=1` in the stats), nothing appeared on screen. No crash, no warning. The overlay simply didn't render. The cause: I added the overlay view to its container with `addView(view)` and no explicit `LayoutParams`. Default behavior is `WRAP_CONTENT`, and since `OverlayView` has no intrinsic content, it's just a custom `View` doing manual canvas drawing, it measured out to 0×0. `onDraw()` was being called the whole time, just onto a canvas with no area to draw into. addView( overlayView, FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT ) ) This is the one I'd flag hardest to anyone stacking a custom-drawn view over a CameraX preview: the pipeline can be entirely correct and you'll still see nothing, because the bug isn't in your detection logic at all. ### 3. SurfaceView doesn't respect view z-order Even after fixing #2, the overlay _still_ didn't show, except for a single frame that flashed the instant I hit Stop. That flash was the clue. `PreviewView` defaults to `ImplementationMode.PERFORMANCE`, which renders through a `SurfaceView`. `SurfaceView` content composites through a separate hardware layer, outside Android's normal view-drawing pass, meaning it can visually sit above other views in the same layout regardless of their z-order in code. My overlay was drawing correctly the entire time. It was just being painted over, every frame, by the camera feed's hardware-composited layer underneath it. The fix is a documented tradeoff, not a hack: previewView.implementationMode = PreviewView.ImplementationMode.COMPATIBLE `COMPATIBLE` forces a `TextureView` instead, which renders as a normal part of the view hierarchy, with predictable layering, at the cost of losing `PERFORMANCE` mode's hardware-layer fast path. For a demo like this, that's the right trade every time. ## The part I'd actually reconsider If I rebuilt this today, I'd add the `COMPATIBLE` implementation mode from the start rather than discovering it two bugs deep. It's a known CameraX behavior. I just hadn't hit it firsthand before. Code's on GitHub: https://github.com/droidchief/lense_bridge
dev.to
September 24, 2026 at 7:46 PM
Call Kotlin or Swift from Flutter without writing a plugin: MethodChannel and EventChannel, registered once in configureFlutterEngine.
https://startdebugging.net/2026/05/how-to-add-platform-specific-code-in-flutter-without-plugins/?utm_source=bluesky&utm_medium=social&utm_campaign=auto
May 5, 2026 at 11:27 AM
Eiii ainda é um bom framework kkkkk mas confesso o esquema para o methodChannel poderia ser muito melhor
June 1, 2025 at 9:54 PM
💳 【Flutter】MethodChannelでSquareアプリを呼び出す
by wamo
https://zenn.dev/wamo/articles/203891a9705de6
【Flutter】MethodChannelでSquareアプリを呼び出す
zenn.dev
February 10, 2024 at 1:15 PM
Awakari App
awakari.com
February 2, 2025 at 4:07 PM