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('...'),
)
Card preset: GlassContainer.card
GlassContainer.card is the card preset (16px padding, 12px superellipse
corners for GlassSurfaceStyle.glass). It is the replacement for the
deprecated GlassCard, and adds a surfaceStyle:
// Native iOS inset-grouped card: flat, opaque, no blur / rim / shadow.
GlassContainer.card(
surfaceStyle: GlassSurfaceStyle.solid,
child: Text('Hello'),
)
iOS renders inset-grouped list cards as flat opaque surfaces, so use GlassSurfaceStyle.solid for cards inside lists and reserve glass for chrome that floats above content.
⚠️ 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:
-
Visual degradation — GlassContainer sets InheritedLiquidGlass.avoidsRefraction to
truefor its entire child subtree. Any GlassEffect descendant falls back to a non-refracting path — the inner glass effect is degraded by design. -
Jelly-physics clipping — With useOwnLayer
= trueon Impeller, the container routes throughLiquidGlass.withOwnLayerwhich 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
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- GlassContainer
- Available extensions
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, Color? color})
-
Creates a glass container.
const
- GlassContainer.card({Key? key, Widget? child, EdgeInsetsGeometry? padding = const EdgeInsets.all(16), EdgeInsetsGeometry? margin, LiquidShape? shape, LiquidGlassSettings? settings, bool useOwnLayer = false, GlassQuality? quality, Clip clipBehavior = Clip.none, double? width, double? height, Color? color, GlassSurfaceStyle surfaceStyle = GlassSurfaceStyle.glass})
-
Creates a card-like container with opinionated defaults.
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
- color → Color?
-
Explicit surface color override, used primarily by solid containers
to provide custom backgrounds or transparency during interactive animations.
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
-
glassContextMenu(
{Key? key, required List< Widget> actions, WidgetBuilder? previewBuilder, bool enabled = true, bool enableHaptics = true, double borderRadius = 32.0, double? previewBorderRadius, double rowBorderRadius = 16.0, BorderRadius? rowCorners, Color? originSlotColor, Color? backgroundColor, LiquidGlassSettings? settings, GlassQuality? quality, double backdropBlur = 0.0, Color? barrierColor, VoidCallback? onOpened, VoidCallback? onDismissed, Duration longPressDuration = const Duration(milliseconds: 700)}) → Widget -
Available on Widget, provided by the GlassContextMenuExtension extension
Wraps this widget in a GlassContextMenu displayingactionson long-press or right-click. -
glassFullScreenCover(
{required bool isPresented, VoidCallback? onDismiss, required WidgetBuilder content, bool enableSwipeToDismiss = true, double dismissThreshold = 140.0, LiquidGlassSettings? settings, GlassQuality? quality}) → Widget -
Available on Widget, provided by the GlassFullScreenCoverExtension extension
Presents a full-viewport modal cover wheneverisPresentedis true. -
Available on Widget, provided by the GlassNavigationTitleExtension extension
Annotates this widget with a navigation title that drives enclosing or descendant GlassAppBar / GlassAppBar.pinned bars (when their explicittitleis null) as well as header accessibility semantics. -
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