pub struct WindowInsets {
pub view_padding: EdgeInsets,
pub view_insets: EdgeInsets,
pub corner_insets: CornerInsets,
}Expand description
The window’s inset state, mirroring Flutter’s ViewportMetrics
(media_query.dart).
Carries the two per-edge sets a shell transports; the third (the derived
safe-area padding) is computed on demand, never
stored:
view_padding— system-UI-occluded edges (status/navigation bars, display cutout). Never includes the IME.view_insets— fully-obscured area, in practice the on-screen keyboard (IME). The status bar is never part of this on either platform.
All values are logical px (see the module docs). Default is
the all-zero state (no occlusion). PartialEq lets a shell compare the
freshly-read platform insets against the last-pushed value and skip a no-op
set_insets.
Fields§
§view_padding: EdgeInsetsSystem-UI-occluded edges (status/navigation bars, cutout), in logical px.
view_insets: EdgeInsetsFully-obscured edges (the IME/keyboard), in logical px.
corner_insets: CornerInsetsWindow-control corners, in logical px; see CornerInsets.
Implementations§
Source§impl WindowInsets
impl WindowInsets
Sourcepub fn new(view_padding: EdgeInsets, view_insets: EdgeInsets) -> Self
pub fn new(view_padding: EdgeInsets, view_insets: EdgeInsets) -> Self
Construct from the two transported per-edge sets; corners are
CornerInsets::ZERO (see with_corner_insets).
Sourcepub fn with_corner_insets(self, corner_insets: CornerInsets) -> Self
pub fn with_corner_insets(self, corner_insets: CornerInsets) -> Self
These insets with the window-control corner_insets set. padding()
is unaffected.
Sourcepub fn padding(&self) -> EdgeInsets
pub fn padding(&self) -> EdgeInsets
The derived safe-area padding: max(0.0, view_padding - view_insets)
per edge (Flutter’s formula, media_query.dart:152-170).
This is what a SafeArea widget insets by — where the IME
(view_insets) overlaps a system-bar edge (view_padding), that edge’s
safe-area padding clamps to zero (the IME already handles keyboard
avoidance for that edge). Computed on demand; never transported.
Sourcepub fn consuming(
self,
left: bool,
top: bool,
right: bool,
bottom: bool,
) -> WindowInsets
pub fn consuming( self, left: bool, top: bool, right: bool, bottom: bool, ) -> WindowInsets
These insets with the safe-area padding on
each enabled edge marked as consumed — the value a widget that has
already padded by those edges hands to its subtree.
Flutter parity: MediaQuery.removePadding as applied by SafeArea. For
each enabled edge, view_padding.<edge> is reduced by
self.padding().<edge> (saturating at zero); view_insets is left
untouched. The invariants are:
consuming(..).padding().<edge> == 0.0on every enabled edge;view_insetsis unchanged, so the IME still reaches descendants for keyboard avoidance;- disabled edges are unchanged in both sets;
consuming(..).corner_insets == self.corner_insets— corners are never consumed;- the operation is idempotent — consuming an already-consumed edge is a
no-op, which is what makes nested
SafeAreas consume only once.