WaveformPlayer class
A customizable audio waveform player widget A complete waveform player widget with audio visualization, play/pause controls, and extensive customization options.
This widget provides a comprehensive audio player interface with:
- Real-time waveform visualization
- Customizable progress slider with multiple thumb shapes
- Play/pause controls with animated effects
- Duration display
- Extensive theming and styling options
Example:
// Using URL
WaveformPlayer(
audioUrl: 'https://example.com/audio.mp3',
waveformHeight: 24.0,
thumbSize: 16.0,
thumbShape: ThumbShape.verticalBar,
activeColor: Colors.blue,
inactiveColor: Colors.grey,
playIconWidget: Icon(Icons.play_circle_filled),
pauseIconWidget: Icon(Icons.pause_circle_filled),
// Or use AnimatedIcons for morphing animation:
animatedIcon: AnimatedIcons.play_pause,
iconSize: 24.0, // Clamped between 12.0 and 40.0
)
// Using Asset
WaveformPlayer(
assetPath: 'assets/audio/sample.mp3',
waveformHeight: 24.0,
thumbSize: 16.0,
thumbShape: ThumbShape.verticalBar,
activeColor: Colors.blue,
inactiveColor: Colors.grey,
glowColor: Colors.blue,
glowDuration: Duration(milliseconds: 1500),
glowRadiusFactor: 0.3,
glowCount: 3,
showGlow: true,
)
// Using Controller
final controller = WaveformPlayerController();
WaveformPlayer(
audioUrl: 'https://example.com/audio.mp3',
controller: controller,
)
// Later: controller.play(), controller.pause(), etc.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- WaveformPlayer
Constructors
-
WaveformPlayer({Key? key, String? audioUrl, String? assetPath, WaveformPlayerController? controller, double waveformHeight = 24.0, double thumbSize = 16.0, ThumbShape thumbShape = ThumbShape.verticalBar, Color? activeColor, Color? inactiveColor, Color? thumbColor, Color? backgroundColor, bool showPlayButton = true, bool showDuration = true, bool autoPlay = false, double playButtonSize = 40.0, Color? playButtonColor, Color? playButtonIconColor, Widget? playIconWidget, Widget? pauseIconWidget, AnimatedIconData? animatedIcon, double? iconSize, TextStyle? durationTextStyle, Color? borderColor, Duration animationDuration = const Duration(milliseconds: 200), ValueChanged<
bool> ? onPlayPause, ValueChanged<Duration> ? onPositionChanged, VoidCallback? onCompleted, ValueChanged<String> ? onError, Color? glowColor, Duration glowDuration = const Duration(milliseconds: 1000), double glowRadiusFactor = 0.25, int glowCount = 2, bool showGlow = true, double barWidth = 4.0, double barSpacing = 1.0}) -
Creates a WaveformPlayer.
const
Properties
- activeColor → Color?
-
Color for the active (played) portion of the waveform
final
- animatedIcon → AnimatedIconData?
-
Custom AnimatedIcons for play/pause animation
final
- animationDuration → Duration
-
Duration of animations (play button, etc.)
final
- assetPath → String?
-
Asset path of the audio file to play
final
- audioUrl → String?
-
URL of the audio file to play
final
- autoPlay → bool
-
Whether to auto-play when loaded
final
- backgroundColor → Color?
-
Background color of the player container
final
- barSpacing → double
-
Spacing between waveform bars
final
- barWidth → double
-
Width of each waveform bar
final
- borderColor → Color?
-
Color of the border
final
- controller → WaveformPlayerController?
-
Controller for programmatic control
final
- durationTextStyle → TextStyle?
-
Text style for duration display
final
- glowColor → Color?
-
Color of the play/pause button glow
final
- glowCount → int
-
Number of glow rings
final
- glowDuration → Duration
-
Duration of the glow animation
final
- glowRadiusFactor → double
-
Radius factor of the glow effect (0.0 to 1.0)
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- iconSize → double?
-
Size of the play/pause icon (clamped between 12.0 and 40.0)
final
- inactiveColor → Color?
-
Color for the inactive (unplayed) portion of the waveform
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- onCompleted → VoidCallback?
-
Callback when playback completes
final
-
onError
→ ValueChanged<
String> ? -
Callback when an error occurs
final
-
onPlayPause
→ ValueChanged<
bool> ? -
Callback when play/pause state changes
final
-
onPositionChanged
→ ValueChanged<
Duration> ? -
Callback when position changes during playback
final
- pauseIconWidget → Widget?
-
Custom widget for pause icon
final
- playButtonColor → Color?
-
Color of the play/pause button background
final
- playButtonIconColor → Color?
-
Color of the play/pause button icon
final
- playButtonSize → double
-
Size of the play/pause button
final
- playIconWidget → Widget?
-
Custom widget for play icon
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showDuration → bool
-
Whether to show the duration text
final
- showGlow → bool
-
Whether to show glow effect
final
- showPlayButton → bool
-
Whether to show the play/pause button
final
- thumbColor → Color?
-
Color of the draggable thumb
final
- thumbShape → ThumbShape
-
Shape of the thumb (circle, verticalBar, etc.)
final
- thumbSize → double
-
Size of the draggable thumb
final
- waveformHeight → double
-
Height of the waveform visualization
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< WaveformPlayer> -
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