-
Notifications
You must be signed in to change notification settings - Fork 30.2k
PlatformView (AndroidView and UIKitView) does not constrain painted content even when parent object provides bounded layout constraints #85171
Description
Steps to Reproduce
- Create a
ConstrainedBoxcontaining anAndroidView(orUIKitView) - Painted content from AndroidView is not constrained or clipped
Code to reproduce: https://github.com/sjschultze/example_zoom_app_boundedwidget/blob/3d222ea4d349c3bb4b82562f7f67d1adf433b357/lib/meeting_screen.dart#L64
Expected results:
- AndroidView content is constrained and scaled; or
- AndroidView content is constrained and clipped
Actual results: AndroidView takes up the full screen because the Android code seeks to use the full screen
According to the documentation:
https://api.flutter.dev/flutter/widgets/AndroidView-class.html
"The widget fills all available space, the parent of this object must provide bounded layout constraints."
https://api.flutter.dev/javadoc/io/flutter/plugin/platform/PlatformView.html
According to DevTools, the widget's parent is in fact providing bounded layout constraints:

But the Android (and iOS) code paints outside of these constraints. This does not seem like expected behavior.
Same behavior if I put the PlatformView in a ClipRect.
Perhaps also relevant is this commit, which seems to attempt to enforce clipping on platform views:
e0ac5da#diff-dc49b2234ad236214c9f647647549f56fa73e0f05d4873f84cfa0c03ff77b66dR86
Both RenderAndroidView and RenderUIKitView extend RenderBox so maybe that's where it would have to be addressed:
| class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin { |
| class RenderUiKitView extends RenderBox { |
RenderBox computes (and uses?) intrinsic dimensions, so maybe that's why it's not respecting the constraints. I swear I read the constraints documentation.
Ideal behavior would be for the Android and iOS view to scale (i.e. from the native code's perspective, it should only "know about" the constrained area and only try to paint to that area). Put another way, it should work like a WebView.
cc: @bdlukaa who seems to know a lot about constraining platform views (#77416)