GlassInteractionStateMixin<T extends StatefulWidget> mixin
State lifecycle mixin for interactive glass container widgets.
Provides isPressed, isFocused, and isHovered ValueNotifiers and their most common Listenable.merge combinations, with guaranteed disposal in dispose.
Why a mixin, not a widget?
Container item widgets in this package (GlassListTile, GlassMenuItem,
_ActionSheetButton, _GlassGroupItemWidget) share the same interaction
state lifecycle but have fundamentally different rendering: distinct
shapes, decorations, scale effects, and external press states. A shared
"wrapper widget" would accumulate all those render differences as
constructor parameters, producing a God Widget.
A mixin supplies only the shared infrastructure — the ValueNotifiers and
their merged Listenables — while leaving each widget's rendering exactly
where it belongs: in its own build method. This mirrors how Flutter's
own framework handles similar problems: SingleTickerProviderStateMixin
provides a Ticker without imposing how the animation is painted;
AutomaticKeepAliveClientMixin keeps a subtree alive without changing
its build output.
Usage
Apply to a State subclass, then use isPressed, isFocused, or isHovered wherever you previously declared them as fields:
class _MyState extends State<MyWidget>
with GlassInteractionStateMixin {
@override
Widget build(BuildContext context) {
return GlassFocusRegion(
isFocusedNotifier: isFocused,
child: GestureDetector(
onTapDown: (_) => isPressed.value = true,
onTapUp: (_) => isPressed.value = false,
onTapCancel: () => isPressed.value = false,
child: ListenableBuilder(
listenable: pressedAndFocused,
builder: (context, child) {
final highlight = isPressed.value || isFocused.value;
return AnimatedContainer(
duration: isPressed.value
? Duration.zero
: const Duration(milliseconds: 150),
color: highlight
? const Color(0x1AFFFFFF)
: const Color(0x00000000),
child: child,
);
},
child: ...,
),
),
);
}
}
Do not update isFocused or isHovered directly; pass them to
GlassFocusRegion via isFocusedNotifier and isHoveredNotifier and
let the region manage them.
- Superclass constraints
- State<
T>
- State<
Properties
- allInteraction ↔ Listenable
-
A Listenable that fires when isPressed, isFocused, or isHovered
change.
latefinal
- context → BuildContext
-
The location in the tree where this widget builds.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
isFocused
→ ValueNotifier<
bool> -
Whether keyboard focus is currently on this widget.
final
-
isHovered
→ ValueNotifier<
bool> -
Whether the pointer is currently hovering over this widget.
final
-
isPressed
→ ValueNotifier<
bool> -
Whether the user is currently pressing this widget.
final
- mounted → bool
-
Whether this State object is currently in a tree.
no setterinherited
- pressedAndFocused ↔ Listenable
-
A Listenable that fires when isPressed or isFocused change.
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- widget → T
-
The current configuration.
no setterinherited
Methods
-
activate(
) → void -
Called when this object is reinserted into the tree after having been
removed via deactivate.
inherited
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
inherited
-
deactivate(
) → void -
Called when this object is removed from the tree.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
didChangeDependencies(
) → void -
Called when a dependency of this State object changes.
inherited
-
didUpdateWidget(
covariant T oldWidget) → void -
Called whenever the widget configuration changes.
inherited
-
dispose(
) → void -
Called when this object is removed from the tree permanently.
override
-
initState(
) → void -
Called when this object is inserted into the tree.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reassemble(
) → void -
Called whenever the application is reassembled during debugging, for
example during hot reload.
inherited
-
setState(
VoidCallback fn) → void -
Notify the framework that the internal state of this object has changed.
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
-
toStringShort(
) → String -
A brief description of this object, usually just the runtimeType and the
hashCode.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited