SoundButton class
A customizable button widget that plays a sound and provides haptic feedback when pressed.
Use this widget to enhance your app's interactivity by adding sound effects (either default or custom) and optional vibrations on button presses.
Example:
SoundButton(
defaultSound: DefaultSound.click,
child: Text('Click Me'),
onPressed: () => print('Button clicked!'),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- SoundButton
Constructors
- SoundButton({Key? key, String? soundPath, DefaultSound? defaultSound, double volume = 1.0, double playbackSpeed = 1.0, bool loopSound = false, bool enableHaptic = true, required Widget child, VoidCallback? onPressed, ButtonStyle? style})
-
Creates a SoundButton with the specified properties.
const
Properties
- child → Widget
-
The child widget to display inside the button.
final
- defaultSound → DefaultSound?
-
The default sound to play, if soundPath is not provided.
final
- enableHaptic → bool
-
Whether to enable haptic feedback (vibration) on press.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- loopSound → bool
-
Whether to loop the sound.
final
- onPressed → VoidCallback?
-
The callback to execute when the button is pressed.
final
- playbackSpeed → double
-
The playback speed (e.g., 1.0 for normal, 2.0 for double speed).
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- soundPath → String?
-
The path to a custom sound file (e.g., 'assets/sounds/custom.mp3').
If provided, this overrides defaultSound.
final
- style → ButtonStyle?
-
The style to apply to the button.
final
- volume → double
-
The volume level for sound playback (0.0 to 1.0).
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< SoundButton> -
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