GlassSurface class Foundations

Declares a region of the screen as glass.

The shape is the engine's own round superellipse — RSuperellipse, the shape a Flutter RoundedRectangleBorder already lowers to — rather than a rounded rectangle, because that is what Apple's material is and because the two differ where it shows: the curvature at the join of the two arcs jumps by 1.6…4.7x on a plain rounded rect and by less on this one, and a bevel's shading carries that jump.

It needs a GlassHost above it to draw glass: the host captures what is painted under the surface, and the surface samples that capture through its finish. Without a host it paints its child over nothing, and the first frame under a new host is the same, because a capture reads the frame that was just painted.

Its child is drawn on top of the glass and is not in the capture.

GlassHost(
  child: Stack(
    children: <Widget>[
      Positioned.fill(child: Image.asset('assets/photo.jpg', fit: BoxFit.cover)),
      Center(
        child: GlassSurface(
          borderRadius: const BorderRadius.all(Radius.circular(28)),
          finish: GlassFinish.clear,
          child: const Padding(
            padding: EdgeInsets.all(20),
            child: Text('Clear glass'),
          ),
        ),
      ),
    ],
  ),
)

Most screens never use it directly: GlassBar, GlassButton and GlassCard are surfaces with a padding, a shape and a label colour chosen for legibility.

See also:

Inheritance

Constructors

GlassSurface({BorderRadius borderRadius = const BorderRadius.all(Radius.circular(24)), GlassFinish? finish, double presence = 1, double materialize = 1, bool labelled = true, GlassFade? fade, GlassRipple? ripple, Widget? child, Key? key})
Glass of borderRadius around child, in the theme's finish unless finish names another.
const

Properties

borderRadius → BorderRadius
The corner radii, in logical pixels.
final
child → Widget?
The widget below this widget in the tree.
finalinherited
fade → GlassFade?
A fade across the glass, or null for glass that is whole everywhere. See GlassFade.
final
finish → GlassFinish?
The optics. Null takes the host's, which is what a screen with one look wants; naming one here is for the surface that differs from its neighbours.
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
labelled → bool
Whether a label is drawn over this glass, so the theme's label floor (GlassThemeData.minLabelContrast) applies to it.
final
materialize → double
How far the glass has materialized, 0 to 1: the finish arriving rather than the shape — blur first, tint last, as Apple's .materialize does. See GlassFinish.materializing. Animate it, or presence, or both.
final
presence → double
How much of the surface is there, 0 to 1. Animate it to make glass appear or leave; see RenderGlassSurface.presence for why it is not a size.
final
ripple → GlassRipple?
The wave this glass makes when touched, or null to take the theme's (GlassThemeData.ripple), which is none by default. Not drawn while the platform asks for reduced motion (MediaQuery.disableAnimationsOf), nor by a member of a fusing group, nor on a rung below GlassTier.full.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() → SingleChildRenderObjectElement
RenderObjectWidgets always inflate to a RenderObjectElement subclass.
inherited
createRenderObject(BuildContext context) → RenderGlassSurface
Creates an instance of the RenderObject class that this RenderObjectWidget represents, using the configuration described by this RenderObjectWidget.
override
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
didUnmountRenderObject(covariant RenderObject renderObject) → void
This method is called when a RenderObject that was previously associated with this widget is removed from the render tree. The provided RenderObject will be of the same type as the one created by this widget's createRenderObject method.
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
updateRenderObject(BuildContext context, covariant RenderGlassSurface renderObject) → void
Copies the configuration described by this RenderObjectWidget to the given RenderObject, which will be of the same type as returned by this object's createRenderObject.
override

Operators

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