GlassContainer class

A foundational glass container widget following Apple's liquid glass design.

This is the base primitive for all container-based glass widgets. It provides a simple glass surface with configurable dimensions, padding, and shape.

Usage Modes

Grouped Mode (default)

Uses LiquidGlass.grouped and inherits settings from parent LiquidGlassLayer:

AdaptiveLiquidGlassLayer(
  settings: LiquidGlassSettings(...),
  child: Column(
    children: [
      GlassContainer(
        child: Text('Hello'),
      ),
      GlassContainer(
        child: Text('World'),
      ),
    ],
  ),
)

Standalone Mode

Creates its own layer with LiquidGlass.withOwnLayer:

GlassContainer(
  useOwnLayer: true,
  settings: LiquidGlassSettings(
    thickness: 30,
    blur: 10,
  ),
  child: Text('Standalone'),
)

Customization Examples

Custom padding and shape:

GlassContainer(
  padding: EdgeInsets.all(20),
  shape: LiquidRoundedSuperellipse(borderRadius: 16),
  child: Text('Padded content'),
)

With constraints:

GlassContainer(
  width: 200,
  height: 100,
  child: Center(child: Text('Fixed size')),
)

With clipping:

GlassContainer(
  clipBehavior: Clip.antiAlias,
  child: Image.network('...'),
)

⚠️ Anti-Pattern: Do Not Place Glass Controls Inside a GlassContainer

GlassContainer is a foundational surface, not a generic wrapper. Placing interactive glass controls inside it causes two problems:

  1. Visual degradation — GlassContainer sets InheritedLiquidGlass.avoidsRefraction to true for its entire child subtree. Any GlassEffect descendant falls back to a non-refracting path — the inner glass effect is degraded by design.

  2. Jelly-physics clipping — With useOwnLayer = true on Impeller, the container routes through LiquidGlass.withOwnLayer which applies its own internal shape clip. Interactive indicator widgets overshoot their bounds during spring animations — that overshoot gets cut.

Interactive glass controls already manage their own surface appearance via backgroundColor and indicatorColor — no outer container is needed.

// ✅ Correct — control manages its own surface
GlassSegmentedControl(
  segments: [...],
  selectedIndex: _index,
  onSegmentSelected: (i) => setState(() => _index = i),
)

// ❌ Anti-pattern — degrades refraction, clips jelly animation
GlassContainer(
  child: GlassSegmentedControl(...),
)
Inheritance

Constructors

GlassContainer({Key? key, Widget? child, double? width, double? height, EdgeInsetsGeometry? padding, EdgeInsetsGeometry? margin, LiquidShape shape = const LiquidRoundedSuperellipse(borderRadius: 16), LiquidGlassSettings? settings, bool useOwnLayer = false, GlassQuality? quality, Clip clipBehavior = Clip.none, AlignmentGeometry? alignment, bool allowElevation = false, double glowIntensity = 0.0, bool platformViewBackdrop = false})
Creates a glass container.
const

Properties

alignment → AlignmentGeometry?
The alignment of the child within the container.
final
allowElevation → bool
Whether to allow elevation effects when in a grouped context.
final
child → Widget?
The widget below this widget in the tree.
final
clipBehavior → Clip
The clipping behavior for the container.
final
glowIntensity → double
Interactive glow intensity for Skia/Web (0.0–1.0).
final
hashCode → int
The hash code for this object.
no setterinherited
height → double?
Height of the container in logical pixels.
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
margin → EdgeInsetsGeometry?
Empty space to surround the glass container.
final
padding → EdgeInsetsGeometry?
Empty space to inscribe inside the glass container.
final
platformViewBackdrop → bool
When true (typically for iOS PlatformViews), forces the BackdropFilter fallback render path instead of the Impeller-native shader. Forwarded to the underlying AdaptiveGlass.
final
quality → GlassQuality?
Rendering quality for the glass effect.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
settings → LiquidGlassSettings?
Glass effect settings for this container.
final
shape → LiquidShape
Shape of the glass container.
final
useOwnLayer → bool
Whether to create its own layer or use grouped glass within an existing layer.
final
width → double?
Width of the container in logical pixels.
final

Methods

build(BuildContext context) → Widget
Describes the part of the user interface represented by this widget.
override
createElement() → StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited