Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn AddToApp

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. Bật content sizing iOS: FlutterViewController.isAutoResizable = true Android: đặt width/height của FlutterView là content_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. Bài viết gốc đăng tại FlutterCook . Bản trên đó là bản được cập nhật mới nhất.

Content-sized Flutter views in native parents

Historically an embedded Flutter view needed a fixed size from its native parent. That made Flutter-inside- UIScrollView or RecyclerView painful. Enable content sizing iOS: FlutterViewController.isAutoResizable = true Android: set width/height of FlutterView to content_wrap and enable content sizing in the manifest/docs flow. Root widget constraints Your Flutter root must tolerate unbounded height (or width). Avoid a top-level ListView that expects a bounded viewport; prefer intrinsic-height layouts or a single-column with shrink-wrapped content. Pitfalls Animations that assume a phone-sized viewport can overflow inside a native list cell. Measure jank: multiple embedded Flutter engines/views still cost memory. Coordinate with keyboard insets from the native side. Originally published on FlutterCook . Read the latest version there — that copy is the one kept up to date.