GlassPress class Foundations
How a pressed glass control responds: it grows by grow while held, and leans up to maxPull toward a finger that drags, stretched up to maxStretch along the drag and squashed across it.
Read by GlassButton from GlassThemeData.press unless the button names its own. none turns it off, and so does the platform's reduced-motion switch.
A feel rather than a measurement — see the numbers on each field. It costs two captures a press and none while the glass moves: the glass grows inside a travel region declared around it (margin past its box) from touch-down until the spring settles, behind a boundary of its own. At rest it costs nothing.
// No swell on one button, and a gentler one everywhere else.
GlassButton(press: GlassPress.none, onPressed: save, child: const Text('Save'))
GlassHost(press: const GlassPress(grow: 8), child: navigator!)
See also:
- GlassDropMotion, the same kind of spec for a control's held drop.
- GlassTravel, the declaration that makes the growth free.
- Annotations
Constructors
- GlassPress({double grow = 12, double maxStretch = 0.05, double maxPull = 3, double pullReach = 12, double stiffness = 500, double damping = 26})
-
A press with the package's defaults: 12 px of growth on the longest side,
up to 3 px of lean and 5% of stretch toward the finger, on a spring with
a damping ratio of about 0.6.
const
Properties
- damping → double
-
The spring's damping, at unit mass. See stiffness.
final
- grow → double
-
How much longer the longest side is while held, logical px; the shorter
side grows by the same factor. A fixed amount rather than a ratio, which
is the hypothesis borrowed (see the file comment): 12 is 1.27x a 44 px
circle and 1.09x a 132 px pill.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- isNone → bool
-
Whether this responds to nothing.
no setter
- maxPull → double
-
The most the glass's centre moves toward a dragging finger, logical px.
final
- maxStretch → double
-
The most the glass stretches along a drag, as a fraction: at 0.05 it is
up to 5% longer toward the finger and 1/1.05 as thick across — the area
is kept.
final
- pullReach → double
-
How far the finger has to drag, logical px, for the lean and the stretch
to reach three quarters of their most (
tanh(1)). The default reaches about 90% at Flutter's touch slop, 18 px, past which a tap is cancelled and the glass springs back.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stiffness → double
-
The spring the growth and the lean follow, at unit mass.
final
Methods
-
copyWith(
{double? grow, double? maxStretch, double? maxPull, double? pullReach, double? stiffness, double? damping}) → GlassPress - This press with the named fields replaced.
-
margin(
Size rest) → Size -
How far past a resting box of
restthe glass can reach, per side — across and down: the growth at maxOvershoot, stretched, and the lean, plus one for the rounding. What the control's travel region adds to its box, and so what the press costs the atlas while it is on: for the defaults, 12.3 px a side on a 44 px circle, and 14.5 across by 7.5 down on a 132 x 44 pill. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
orNoneUnderReducedMotion(
BuildContext context) → GlassPress -
none when
contextasks for reduced motion; this otherwise. -
rect(
Size rest, double press, Offset finger) → Rect -
Where the glass of a control resting at
restis drawn, in the resting box's coordinates, atpress(0 at rest, 1 held — more or less while the spring overshoots) with the fingerfingerpx from where it came down. -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Methods
-
resolve(
BuildContext context, GlassPress? declared) → GlassPress -
The press a control in
contextuses: its owndeclared, else the theme's — and none either way under reduced motion.
Constants
- maxOvershoot → const double
- The most the press's spring is allowed to carry the growth past full, as a fraction of grow — the overshoot margin reserves room for. The default spring overshoots by about 10%.
- none → const GlassPress
- No response at all: the control keeps its box, and builds no region for it.