📐 Deep Dive · Advanced

Flutter view co theo nội dung trong native parent

Trước đây view Flutter nhúng cần size cố định từ native parent. Điều đó khiến Flutter bên trong UIScrollView hay RecyclerView rất đau.

Sơ đồ: Content-sized Views

Bật content sizing

  • iOS: FlutterViewController.isAutoResizable = true
  • Android: đặt width/height của FlutterViewcontent_wrap và bật content sizing theo docs.

Ràng buộc root widget

Root Flutter phải chịu được unbounded height (hoặc width). Tránh ListView top-level kỳ vọng viewport bị chặn; ưu tiên layout intrinsic-height hoặc shrink-wrapped.

Cạm bẫy

  • Animation giả định viewport cỡ phone có thể overflow trong cell list native.
  • Đo jank: nhiều engine/view Flutter nhúng vẫn tốn memory.
  • Đồng bộ keyboard inset từ phía native.
#Flutter#AddToApp#iOS#Android