Skip to content

PlatformView (AndroidView and UIKitView) does not constrain painted content even when parent object provides bounded layout constraints #85171

@sjschultze

Description

@sjschultze

Steps to Reproduce

  1. Create a ConstrainedBox containing an AndroidView (or UIKitView)
  2. 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:

  1. AndroidView content is constrained and scaled; or
  2. 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:
image

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: invalidIssue is closed as not valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions