ShimmerButton class
A button with a periodic shimmer sweep across its surface, meant for primary calls to action.
ShimmerButton(
onPressed: () => debugPrint('Pressed!'),
child: const Text('Get started'),
)
A diagonal highlight band sweeps across the button, pauses for shimmerInterval, then sweeps again. The sweep direction follows the ambient Directionality. Pressing scales the button down slightly; onPressed fires immediately on tap-up and never waits for animations.
The button is exposed to assistive technology as a button and can be activated with the keyboard (Enter or Space) when focused; keyboard focus shows a visible highlight border.
When onPressed is null or enabled is false the button renders in a dimmed disabled style with no shimmer and no press feedback. Under reduced motion the shimmer never runs and the press feedback is skipped, but the button stays fully functional.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- ShimmerButton
Constructors
- ShimmerButton({Key? key, required Widget child, required VoidCallback? onPressed, Color? backgroundColor, Color? shimmerColor, Duration shimmerDuration = const Duration(milliseconds: 2200), Duration shimmerInterval = const Duration(milliseconds: 1200), Duration pressDuration = const Duration(milliseconds: 120), Curve curve = Curves.easeInOut, BorderRadius borderRadius = const BorderRadius.all(Radius.circular(12)), EdgeInsetsGeometry padding = const EdgeInsets.symmetric(horizontal: 24, vertical: 14), double elevation = 0, bool enableHaptics = false, bool enabled = true, String? semanticLabel})
-
Creates a shimmer button.
const
Properties
- backgroundColor → Color?
-
Background color of the button. Defaults to the theme's
colorScheme.primary.final - borderRadius → BorderRadius
-
Corner radius of the button surface. Defaults to a 12 pixel circular
radius on all corners.
final
- child → Widget
-
The content of the button, typically a Text.
final
- curve → Curve
-
Curve applied to the sweep and press animations. Defaults to
Curves.easeInOut.
final
- elevation → double
-
Elevation of the button surface. Defaults to 0.
final
- enabled → bool
-
When false the button renders disabled, exactly as if onPressed
were null.
final
- enableHaptics → bool
-
Whether a light haptic impact is triggered on press. Defaults to
false.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- onPressed → VoidCallback?
-
Called immediately on tap-up or keyboard activation. When null the
button renders disabled.
final
- padding → EdgeInsetsGeometry
-
Padding around child. Defaults to 24 horizontal by 14 vertical.
final
- pressDuration → Duration
-
Length of the press scale animation. Defaults to 120 milliseconds.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- semanticLabel → String?
-
Optional semantic label announced for the button.
final
- shimmerColor → Color?
-
Color of the shimmer highlight band. Defaults to the theme's
colorScheme.onPrimaryat 35 percent alpha.final - shimmerDuration → Duration
-
Length of one shimmer sweep. Defaults to 2200 milliseconds.
final
- shimmerInterval → Duration
-
Pause between two consecutive sweeps. Defaults to 1200 milliseconds.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< ShimmerButton> -
Creates the mutable state for this widget at a given location in the tree.
override
-
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