GlassContainer class

A widget that creates a glassmorphism effect by blurring the background and applying a translucent container with optional border and shadow.

The GlassContainer applies a blur effect to the background behind it, and overlays a semi-transparent container with customizable opacity, border, background color, and shadow.

Example usage:

GlassContainer(
  blur: 20,
  opacity: 0.3,
  borderRadius: BorderRadius.circular(15),
  borderColor: Colors.white.withValues(alpha: 0.3),
  borderWidth: 1.5,
  shadowColor: Colors.black.withValues(alpha: 0.1),
  shadowBlurRadius: 10,
  padding: EdgeInsets.all(20),
  child: Text("Glassmorphism!"),
)
Inheritance

Constructors

GlassContainer({Key? key, required Widget child, double blur = 15, double opacity = 0.2, BorderRadius borderRadius = const BorderRadius.all(Radius.circular(20)), Color? backgroundColor, Color borderColor = const Color.fromARGB(77, 255, 255, 255), double borderWidth = 1.0, Color shadowColor = Colors.transparent, double shadowBlurRadius = 0, EdgeInsetsGeometry padding = const EdgeInsets.all(0)})
const

Properties

backgroundColor Color?
The color of the container's background. Defaults to white with opacity set by opacity.
final
blur double
The sigma value for the Gaussian blur effect. Higher values create more blur.
final
borderColor Color
The color of the border around the container. Defaults to white with 30% opacity.
final
borderRadius BorderRadius
The border radius of the glass container's rounded corners.
final
borderWidth double
The width of the border. Defaults to 1.0.
final
child Widget
The child widget displayed inside the glass container.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
opacity double
The opacity of the white overlay. Value between 0.0 (fully transparent) and 1.0 (fully opaque).
final
padding EdgeInsetsGeometry
The padding inside the glass container around the child.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shadowBlurRadius double
The blur radius of the shadow. Defaults to 0 (no shadow).
final
shadowColor Color
The color of the shadow cast by the container. Defaults to fully transparent (no shadow).
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