GlassToggle class

A Liquid Glass toggle button mirroring SwiftUI's Toggle(...).toggleStyle(.button).

GlassToggle.button is a pressed/unpressed capsule toggle control that transitions between standard refractive glass (GlassButtonStyle.filled) when off and accent-tinted prominent glass (GlassButtonStyle.prominent) when on — matching native iOS 26/27 .toggleStyle(.button).buttonStyle(.glass).

It is the native SwiftUI primitive superseding Material-style chips and horizontal filter strips: compose multiple GlassToggle.button widgets in a Wrap or horizontal SingleChildScrollView / ListView for filter bars, formatting toolbars, and multi-select option rows.

Visual Behavior (iOS 26 / iOS 27 Calibrated)

Usage

Text & Icon Filter Toggle

GlassToggle.button(
  value: isStarred,
  onChanged: (next) => setState(() => isStarred = next),
  icon: Icon(isStarred ? CupertinoIcons.star_fill : CupertinoIcons.star),
  label: 'Starred',
)

Icon-Only Toggle

GlassToggle.button(
  value: isMuted,
  onChanged: (next) => setState(() => isMuted = next),
  icon: Icon(isMuted ? CupertinoIcons.speaker_slash_fill : CupertinoIcons.speaker_2),
  semanticLabel: 'Mute',
)

Custom Tint & Solid Surface

GlassToggle.button(
  value: isFilterActive,
  onChanged: (next) => setState(() => isFilterActive = next),
  label: 'Unread',
  activeColor: CupertinoColors.systemOrange,
  surfaceStyle: GlassSurfaceStyle.solid,
)
Inheritance
Available extensions

Constructors

GlassToggle.button({required bool value, required ValueChanged<bool>? onChanged, Key? key, String? label, Widget? icon, Widget? child, Color? activeColor, Color? foregroundColor, Color? activeForegroundColor, TextStyle? labelStyle, double iconSize = 17.0, double spacing = 6.0, EdgeInsetsGeometry? padding, double minHeight = 34.0, double? width, double? height, LiquidShape shape = const LiquidRoundedSuperellipse(borderRadius: 100), GlassSurfaceStyle? surfaceStyle, Color? color, LiquidGlassSettings? settings, bool useOwnLayer = false, GlassQuality? quality, bool platformViewBackdrop = false, bool enableHaptics = true, double? interactionScale, double stretch = 0.3, double? glowRadius, bool anchorStretch = true, AnchorStretchSettings? anchorStretchSettings, FocusNode? focusNode, bool autofocus = false, bool canRequestFocus = true, String? semanticLabel})
Creates a capsule toggle button matching SwiftUI Toggle(.button).
const

Properties

activeColor → Color?
Accent fill/tint color used when value is true.
final
activeForegroundColor → Color?
Foreground color for text and icon when value is true.
final
anchorStretch → bool
Whether the toggle anchors in place while stretching toward the finger.
final
anchorStretchSettings → AnchorStretchSettings?
Fine-tuning for anchor stretch behavior. Forwarded to GlassButton.custom.
final
autofocus → bool
Whether this toggle requests keyboard focus automatically on mount.
final
canRequestFocus → bool
Whether this toggle can receive keyboard focus.
final
child → Widget?
Optional custom content widget replacing label and icon.
final
color → Color?
Explicit resting fill color override when value is false and the resolved surfaceStyle is GlassSurfaceStyle.solid.
final
enableHaptics → bool
Whether to emit a HapticFeedback.selectionClick when toggled.
final
focusNode → FocusNode?
Externally provided focus node for keyboard navigation.
final
foregroundColor → Color?
Foreground color for text and icon when value is false.
final
glowRadius → double?
Specular touch glow radius forwarded to GlassButton.custom.
final
hashCode → int
The hash code for this object.
no setterinherited
height → double?
Optional explicit height override in logical pixels.
final
icon → Widget?
Optional leading icon widget (or standalone icon when label is null).
final
iconSize → double
Size of icon in logical pixels.
final
interactionScale → double?
Scale factor applied when pressed. Forwarded to GlassButton.custom.
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
label → String?
Optional text label displayed inside the capsule.
final
labelStyle → TextStyle?
Text style override merged onto the default iOS 26/27 17 pt body style.
final
minHeight → double
Minimum height of the capsule in logical pixels when height is null.
final
onChanged → ValueChanged<bool>?
Called with the toggled boolean value (!value) when the user activates the button via touch, keyboard (Space/Enter), or assistive technology.
final
padding → EdgeInsetsGeometry?
Internal padding around the toggle content.
final
platformViewBackdrop → bool
Forces the live BackdropFilter fallback path when floating over an iOS PlatformView (map, camera, video). Forwarded to GlassButton.custom.
final
quality → GlassQuality?
Rendering quality override for the glass effect.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
semanticLabel → String?
Explicit semantic label for assistive technology (VoiceOver, TalkBack).
final
settings → LiquidGlassSettings?
Glass effect settings forwarded to GlassButton.custom.
final
shape → LiquidShape
Shape of the toggle button.
final
spacing → double
Horizontal gap between icon and label when both are provided.
final
stretch → double
Drag-stretch intensity forwarded to GlassButton.custom.
final
surfaceStyle → GlassSurfaceStyle?
How the toggle's surface is painted.
final
useOwnLayer → bool
Whether to create its own LiquidGlassLayer or share an ancestor layer.
final
value → bool
Whether the toggle button is currently on (true) or off (false).
final
width → double?
Optional explicit width override 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, double menuWidth = 250.0, 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 displaying actions on 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 whenever isPresented is 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 explicit title is 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