kGlassCapsule top-level constant Foundations
A radius larger than any box, which is how a capsule is declared.
The engine scales radii that do not fit — _RRectLike.scaleRadii, Skia's own
rule — so a uniform radius past the box comes out at half the shorter side,
which is a stadium at every size. That is what GlassButton and GlassBar
want: Apple uses a pill for controls, never a squircle.
It has to be declared rather than derived because a BorderRadius is a
value with no size in it, and the size only exists after layout. The
alternative — a LayoutBuilder around every control — puts a build inside
the layout phase to learn something the engine already knows.
⚠️ Read back through RenderGlassSurface.shape, which scales it, and not
raw: RSuperellipse.contains uses the radii as given, so an unscaled
capsule reads as an ellipse — 9425 px² against the 11 214 the engine draws
on a 200x60 box, 16% low.
GlassSurface(
borderRadius: kGlassCapsule,
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: Text('Capsule'),
),
)
Implementation
const BorderRadius kGlassCapsule = BorderRadius.all(Radius.circular(1e9));