GlassAdaptive class Foundations
How a GlassHost's glass reads its own backdrop: pass one as
GlassHost.adaptive to turn it on.
GlassHost(
adaptive: const GlassAdaptive(),
child: Stack(children: <Widget>[photo, Positioned(top: 48, child: GlassBar(child: title))]),
)
What it costs. Nothing on a frame that keeps its capture, which is every
frame of a still screen. On a frame that captures — a scroll, an animation
under the glass — one picture of one drawImageRect per surface, recorded
on the UI thread (microseconds), and at most once per interval a
rasterization of it into a texture of 4 × 4 pixels per surface and a copy of
that texture back to the CPU, both asynchronous. On Impeller and Skia the
copy is a few hundred bytes queued behind the frame's own work; the frame
that asked does not wait for it.
On the web it is dearer, and the default interval is longer there for
that reason. CanvasKit answers Picture.toImage by drawing into a surface
and reading its pixels back synchronously — the same stall the capture
itself pays on that renderer (see the README's Platforms section) — so each
read is a GPU flush on the frame it lands in, however small the texture.
Skwasm reads on its own thread and pays less. One read a second is the
default on both; raise interval further on CanvasKit if the screen
scrolls a lot.
What a reading replaces
A finish a surface, a component, the host or an inner GlassTheme names is
held: no reading re-picks it, and only the label over it follows the
reading. Otherwise the finish is .regular and its branch is the
reading's, picked by GlassFinish.regular against the appearance's
threshold. Under GlassThemeData.richBackdrop the reading moves only the
branch, and the label stays chosen against every backdrop.
Note: a raw GlassSurface does not adapt on its own. GlassBar, GlassCard and GlassButton do; a custom component installs GlassThemeData.adaptedTo around its glass with the reading the host publishes.
See also:
- GlassHost.adaptive, where it is turned on.
- GlassBackdropReading, what one glass read.
- GlassFinish.regular, the branch a reading picks.
- Adaptive glass on the site.
- Annotations
Constructors
- GlassAdaptive({double band = kDefaultBand, Duration hold = kDefaultHold, Duration interval = kDefaultInterval, Duration duration = kDefaultDuration})
-
Reads the backdrop with the default band, hold, interval and duration.
const
Properties
- band → double
-
How far, in code values of luma (GlassFinish.levelOf), a reading must
be from the one the verdict was taken from to move it. 12 by default.
final
- duration → Duration
-
How long a component takes to cross between branches. 300 ms by default,
eased in and out — taste; Apple's own crossing was not timed. None under
MediaQuery.disableAnimations.final - hashCode → int
-
The hash code for this object.
no setteroverride
- hold → Duration
-
The least time between two moves of one glass's verdict. 600 ms by
default — taste, as band is: long enough that content scrolling past
a threshold moves the glass once rather than once per row, and short
enough that a screen settled over a new backdrop follows it within a
glance. A reading that arrives inside the hold is kept, and taken when the
hold ends if nothing newer has replaced it.
final
- interval → Duration
-
The least time between two read-backs. Captures that arrive sooner are
read together when it has passed — the newest of them, once.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Constants
- kDefaultBand → const double
- band's default.
- kDefaultDuration → const Duration
- duration's default.
- kDefaultHold → const Duration
- hold's default.
- kDefaultInterval → const Duration
- interval's default: 250 ms natively, a second on the web.