BouncyPressable class
Adds a bouncy press effect to any widget.
BouncyPressable(
onTap: () => openProduct(product),
child: ProductCard(product),
)
It handles keyboard activation, screen readers, reduced motion, and mouse
cursors, and needs no Material ancestor. For a complete button with a 3D
depth effect, use BouncyButton.
Nesting: when one pressable contains another, pressing the inner one
leaves the outer one still. Other controls inside, such as a TextField,
can't tell it they are pressed, so the outer one may dip while held on them.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- BouncyPressable
Constructors
- BouncyPressable({Key? key, required Widget child, required VoidCallback? onTap, VoidCallback? onLongPress, GestureTapDownCallback? onTapDown, GestureTapUpCallback? onTapUp, VoidCallback? onTapCancel, bool enabled = true, double scaleFactor = 0.95, Duration duration = const Duration(milliseconds: 120), Duration? reverseDuration, Curve curve = Curves.easeOut, Curve? reverseCurve, BouncyPressSpring? spring, BouncyHapticFeedbackType? haptic, bool enableSound = false, VoidCallback? onPressSound, MouseCursor? cursor, HitTestBehavior? hitTestBehavior, FocusNode? focusNode, bool autofocus = false, Color focusColor = const Color(0xFF1E88E5), BorderRadius focusBorderRadius = const BorderRadius.all(Radius.circular(8)), String? semanticLabel, bool semanticsButton = true, Duration? cooldown})
-
Creates a pressable wrapper.
const
Properties
- autofocus → bool
-
Whether to request focus initially.
final
- child → Widget
-
The widget to add the effect to.
final
- cooldown → Duration?
-
How long to ignore presses after onTap or onLongPress runs, so a
quick double tap doesn't run it twice.
final
- cursor → MouseCursor?
-
The mouse cursor. Defaults to a click cursor when enabled.
final
- curve → Curve
-
Curve of the press.
final
- duration → Duration
-
Duration of the press.
final
- enabled → bool
-
Whether the widget responds to input.
final
- enableSound → bool
-
Whether to play the system click sound on a press. The platform may
have no such sound, and web plays nothing.
final
- focusBorderRadius → BorderRadius
-
The corners of the keyboard focus ring.
final
- focusColor → Color
-
The color of the ring shown when the widget has keyboard focus.
final
- focusNode → FocusNode?
-
An optional focus node.
final
- haptic → BouncyHapticFeedbackType?
-
Haptic feedback for a press. Off by default.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hitTestBehavior → HitTestBehavior?
-
How the widget behaves during hit testing. Defaults to
HitTestBehavior.opaque.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- onLongPress → VoidCallback?
-
Called when the widget is long-pressed.
final
- onPressSound → VoidCallback?
-
Called on a press, to play a sound of your own.
final
- onTap → VoidCallback?
-
Called when the widget is tapped or activated.
final
- onTapCancel → VoidCallback?
-
Called when a press ends without a tap, such as when the finger moves
away, a long press takes over, or the widget is disabled while held.
final
- onTapDown → GestureTapDownCallback?
-
Called when a press starts.
final
- onTapUp → GestureTapUpCallback?
-
Called when a press ends with a tap, before onTap.
final
- reverseCurve → Curve?
-
Curve of the release. Defaults to curve.
final
- reverseDuration → Duration?
-
Duration of the release. Defaults to duration.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scaleFactor → double
-
How far the widget shrinks when pressed, from 0.0 to 1.0.
final
- semanticLabel → String?
-
The screen reader label, added to any labels from child.
final
- semanticsButton → bool
-
Whether screen readers announce this as a single button.
final
- spring → BouncyPressSpring?
-
Spring physics for the press. When set, duration, reverseDuration,
curve, and reverseCurve are not used.
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
-
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