preferredSize property
The size this widget would prefer if it were otherwise unconstrained.
In many cases it's only necessary to define one preferred dimension.
For example the Scaffold only depends on its app bar's preferred
height. In that case implementations of this method can just return
Size.fromHeight(myAppBarHeight).
Implementation
@override
Size get preferredSize {
final minimized = _effectiveMinimized;
final isMinimizable = _placement == _GlassTabBarPlacement.minimizable;
final isMorphing =
_placement == _GlassTabBarPlacement.searchable || isMinimizable;
// Base pill height. The searchable variant alternates between barHeight
// (expanded) and searchBarHeight (inline/mini) — use whichever is active.
// Both branches multiply verticalPadding by 2 (top + bottom) to match
// the symmetric Padding applied inside AdaptiveLiquidGlassLayer.
final effectivePillH = (isMorphing && minimized)
? searchBarHeight + verticalPadding * 2
: barHeight + verticalPadding * 2;
double total = effectivePillH;
// In inline mode the accessory sits BESIDE the pill (no extra height).
// This MUST resolve identically to the layout engine's own call, or the
// scaffold reserves a height the bar does not draw.
final isInline = resolveAccessoryPlacement(
explicit: bottomAccessoryPlacement,
minimized: minimized,
isMinimizablePlacement: isMinimizable,
) ==
GlassTabBarAccessoryPlacement.inline;
if (bottomAccessory != null &&
!isInline &&
bottomAccessoryEnabled &&
bottomAccessoryHeight != null) {
// Guard: gapAdjustment only makes sense in the searchable placement when
// both heights differ. For .bottom placement isSearchActive is always false
// so effectivePillH == barHeight + vertPad*2 and gapAdjustment == 0.
final gapAdjustment =
(isMorphing && minimized) ? barHeight - searchBarHeight : 0.0;
total = effectivePillH -
gapAdjustment +
bottomAccessorySpacing +
bottomAccessoryHeight!;
}
return Size.fromHeight(total);
}