You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0a291d1
Browse filesBrowse the repository at this point in the historyBrowse files
[web] Report env(safe-area-inset-*) as FlutterView.viewPadding
`SafeArea` has always been a no-op on the web because nothing ever fed
the device safe area into the framework. Two things were missing.
1. `FullPageEmbeddingStrategy` removed every `<meta name="viewport">` on
the page and wrote its own without `viewport-fit`. An app that opted
into a full-bleed layout with `viewport-fit=cover` had that opt-in
deleted at startup, and WebKit then kept laying the app out inside the
safe area, so `env(safe-area-inset-*)` had nothing to report. This is
why the workarounds in the issue never worked. The `viewport-fit` of
the last viewport meta tag on the page, which is the one the browser
itself honours, is now carried over to the tag that the engine writes,
and, as a result, across hot restarts too. The "this tag will be
replaced" warning now names the descriptors that are actually being
dropped, and stays quiet when none are, so an app following the web
template's advice no longer provokes a warning on every debug run.
2. Nothing in `web_ui` read `env(safe-area-inset-*)`. `DimensionsProvider`
gains `computeSafeAreaInsets()`. `FullPageDimensionsProvider`
implements it by reading the values back from a `display: none` probe
element whose paddings are set to `env(...)`; the browser resolves
`env()` at computed-value time, so no layout or paint is involved.
`CustomElementDimensionsProvider` reports zero, because the host
application is the one that positions an embedded view on the page.
`EngineFlutterView.viewPadding` is now backed by those insets, computed
lazily and recomputed on the same events that recompute the physical
size, and `padding` is `viewPadding` minus `viewInsets`, clamped at zero,
matching the other platforms: when the on-screen keyboard covers the
bottom safe area, the bottom padding goes to zero.
Parsing a `viewport-fit` descriptor lives in one new file,
`view_embedder/viewport_fit.dart`, used both by the strategy that writes
the tag and by the provider that reads it back, so that the two sides
cannot drift apart over the exact spelling of a `content` attribute.
The insets are only reported for a page that declared `viewport-fit=cover`
itself. That is a stricter rule than the one the browser applies to
`env()`: on an iPhone 17 Pro (iOS 18.7, WebKit 605.1.15, Safari 26.1)
`env(safe-area-inset-bottom)` is `20px` in landscape whether or not the
page is full-bleed, and passing that on would have moved the content of
every existing Flutter web app on iOS, including the ones that ask for
nothing. A page that never declared `viewport-fit` keeps a byte-identical
viewport meta tag and a `viewPadding` of `ViewPadding.zero`, exactly as
before this change.
Apps that do declare `viewport-fit=cover` in their `index.html` change,
and that is the point of the fix: the browser stops keeping them within
the safe area. On the device above, a Flutter page in landscape reports
`window.innerWidth` of 750 against 874 for a plain HTML control that
declares the same tag, a difference of exactly the `62 + 62` of left and
right inset the control reports. Content that is not wrapped in a
`SafeArea` moves under the display cutout and the rounded corners, which
is what `viewport-fit=cover` asks the browser for.
The post-change behaviour is covered by unit tests; it has not been
measured on a device, and `env(safe-area-inset-top)` was zero in every
device reading taken, so the top axis in particular rests on unit
coverage alone.
The `flutter create` web template gains the tag, commented out, next to
the guidance it already carries for `<base href>`.
`systemGestureInsets` is deliberately left at zero. `env()` describes the
parts of the viewport obstructed by the device, not the parts the system
reserves for its own gestures, and browsers do not expose the latter.
This covers full-page embeddings only. A view hosted in a custom element
still reports zero, so the issue stays open for embedded and multi-view
apps.
See flutter#84833
Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/view_embedder/dimensions_provider/custom_element_dimensions_provider.dart
+15Lines changed: 15 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -99,4 +99,19 @@ class CustomElementDimensionsProvider extends DimensionsProvider {
Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/view_embedder/dimensions_provider/full_page_dimensions_provider.dart
Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/view_embedder/embedding_strategy/full_page_embedding_strategy.dart
0 commit comments