waveform_visualizer 1.0.0 
waveform_visualizer: ^1.0.0 copied to clipboard
A beautiful animated waveform widget for Flutter with real-time visualization capabilities.
Waveform Visualizer #
A beautiful animated waveform widget for Flutter with real-time visualization capabilities. Perfect for audio applications, voice recorders, and music visualizers.
โจ Features #
- ๐ต Real-time Waveform Visualization: Beautiful animated waveforms that respond to amplitude data
 - ๐จ Multiple Styles: Choose from bars, line, filled, and circular waveform styles
 - ๐ Customizable Appearance: Full control over colors, gradients, stroke width, and animations
 - ๐ฑ Responsive Design: Adapts beautifully to different screen sizes and orientations
 - ๐ Smooth Animations: Fluid animations with customizable pulse effects
 - โก High Performance: Optimized custom painter for smooth 60fps animations
 - ๐ง Easy Integration: Simple API that works with any audio input source
 
๐ธ Screenshots #
๐ Installation #
Add this to your package's pubspec.yaml file:
dependencies:
  waveform_visualizer: ^1.0.0
Then run:
flutter pub get
๐ Usage #
Basic Setup #
Import the package and initialize it:
import 'package:waveform_visualizer/waveform_visualizer.dart';
void main() {
  WaveformVisualizer.initialize();
  runApp(MyApp());
}
Simple Waveform Widget #
Create a basic waveform visualization:
class MyWaveformPage extends StatefulWidget {
  @override
  _MyWaveformPageState createState() => _MyWaveformPageState();
}
class _MyWaveformPageState extends State<MyWaveformPage> {
  late WaveformController _controller;
  @override
  void initState() {
    super.initState();
    _controller = WaveformController();
  }
  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: WaveformWidget(
          controller: _controller,
          height: 200,
          style: WaveformStyle(
            waveColor: Colors.cyan,
            backgroundColor: Colors.black,
            waveformStyle: WaveformDrawStyle.bars,
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          if (_controller.isActive) {
            _controller.stop();
          } else {
            _controller.start();
          }
        },
        child: Icon(_controller.isActive ? Icons.stop : Icons.play_arrow),
      ),
    );
  }
}
Connecting to Microphone #
To use with real microphone input, update the amplitude with your audio data:
// Example with a hypothetical audio package
void onAudioData(List<double> audioSamples) {
  // Calculate RMS amplitude from audio samples
  double amplitude = calculateRMS(audioSamples);
  
  // Update the waveform (amplitude should be 0.0 to 1.0)
  _controller.updateAmplitude(amplitude);
}
double calculateRMS(List<double> samples) {
  double sum = 0.0;
  for (double sample in samples) {
    sum += sample * sample;
  }
  return sqrt(sum / samples.length);
}
Advanced Controller Configuration #
// Configure controller for optimal smoothness
_controller = WaveformController(
  maxDataPoints: 80,              // Data history size
  updateInterval: Duration(milliseconds: 33), // 30fps update rate
  smoothingFactor: 0.85,          // Smoothing intensity (0.0-1.0)
);
๐จ Customization #
Waveform Styles #
Choose from multiple visualization styles:
// Bar style (default)
WaveformStyle(waveformStyle: WaveformDrawStyle.bars)
// Line style
WaveformStyle(waveformStyle: WaveformDrawStyle.line)
// Filled style
WaveformStyle(waveformStyle: WaveformDrawStyle.filled)
// Circular style
WaveformStyle(waveformStyle: WaveformDrawStyle.circular)
Custom Styling #
Customize the appearance with rich styling options:
WaveformStyle(
  waveColor: Colors.cyan,
  backgroundColor: Colors.black,
  strokeWidth: 3.0,
  showGradient: true,
  gradientBegin: Alignment.topCenter,
  gradientEnd: Alignment.bottomCenter,
  barCount: 60,
  barSpacing: 2.0,
  animationDuration: Duration(milliseconds: 150),
)
Style Properties #
| Property | Type | Default | Description | 
|---|---|---|---|
waveColor | 
Color | 
Colors.blue | 
Primary color of the waveform | 
backgroundColor | 
Color | 
Colors.black | 
Background color | 
strokeWidth | 
double | 
2.0 | 
Width of waveform lines/bars | 
showGradient | 
bool | 
true | 
Enable gradient effects | 
gradientBegin | 
Alignment | 
topCenter | 
Gradient start point | 
gradientEnd | 
Alignment | 
bottomCenter | 
Gradient end point | 
waveformStyle | 
WaveformDrawStyle | 
bars | 
Visualization style | 
barCount | 
int | 
50 | 
Number of bars (bar style only) | 
barSpacing | 
double | 
2.0 | 
Space between bars | 
animationDuration | 
Duration | 
100ms | 
Animation speed | 
๐๏ธ Controller API #
WaveformController Methods #
| Method | Description | 
|---|---|
start() | 
Start the waveform visualization | 
stop() | 
Stop the visualization | 
reset() | 
Reset all data points to zero | 
updateAmplitude(double) | 
Update with new amplitude (0.0-1.0) | 
generateTestPattern() | 
Generate demo animation pattern | 
Controller Properties #
| Property | Type | Description | 
|---|---|---|
isActive | 
bool | 
Whether visualization is running | 
currentAmplitude | 
double | 
Current amplitude value | 
dataPoints | 
List<WaveformPoint> | 
Historical amplitude data | 
maxDataPoints | 
int | 
Maximum data points to store | 
๐ฏ Real-World Example #
Here's a complete example with multiple waveform styles:
import 'package:flutter/material.dart';
import 'package:waveform_visualizer/waveform_visualizer.dart';
class WaveformShowcase extends StatefulWidget {
  @override
  _WaveformShowcaseState createState() => _WaveformShowcaseState();
}
class _WaveformShowcaseState extends State<WaveformShowcase> {
  late WaveformController _controller;
  WaveformDrawStyle _currentStyle = WaveformDrawStyle.bars;
  @override
  void initState() {
    super.initState();
    _controller = WaveformController();
    _controller.start(); // Auto-start with demo data
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xFF0D1117),
      appBar: AppBar(
        title: Text('๐ต Waveform Showcase'),
        backgroundColor: Color(0xFF161B22),
      ),
      body: Column(
        children: [
          Expanded(
            child: Center(
              child: WaveformWidget(
                controller: _controller,
                height: 200,
                style: WaveformStyle(
                  waveColor: Colors.cyan,
                  backgroundColor: Color(0xFF0D1117),
                  waveformStyle: _currentStyle,
                  showGradient: true,
                  strokeWidth: 3.0,
                ),
              ),
            ),
          ),
          Padding(
            padding: EdgeInsets.all(16.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: WaveformDrawStyle.values.map((style) {
                return ElevatedButton(
                  onPressed: () => setState(() => _currentStyle = style),
                  child: Text(style.name.toUpperCase()),
                  style: ElevatedButton.styleFrom(
                    backgroundColor: _currentStyle == style 
                        ? Colors.cyan 
                        : Colors.grey[700],
                  ),
                );
              }).toList(),
            ),
          ),
        ],
      ),
    );
  }
  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}
๐ฑ Example App #
Check out the example directory for a complete demo application showcasing all features:
- Multiple waveform styles
 - Real-time style switching
 - Color customization
 - Interactive controls
 - Test pattern generation
 
To run the example:
cd example
flutter run
๐งช Testing #
Run the comprehensive test suite:
flutter test
The package includes tests for:
- โ Waveform controller functionality
 - โ Data point management
 - โ Style configuration
 - โ Animation behavior
 - โ Edge cases and error handling
 
๐ง Performance Tips #
- Optimize Data Points: Use fewer 
maxDataPointsfor better performance on lower-end devices (recommended: 50-100) - Adjust Update Frequency: Use 30-60fps update interval (
Duration(milliseconds: 33)for 30fps) - Choose Appropriate Styles: Bar and line styles are more performant than filled or circular
 - Control Bar Count: Keep bar count between 20-60 for smooth animations
 - Use Smoothing: Higher 
smoothingFactor(0.8-0.9) reduces jerkiness but adds slight delay - Optimize for Device: Lower settings on older devices, higher on flagship phones
 
Smoothness Optimizations #
The package includes several built-in optimizations for smooth animations:
- Amplitude Smoothing: Configurable smoothing factor to reduce jerkiness
 - Interpolation: Linear interpolation between data points for bar visualization
 - Moving Average Filter: 3-point moving average for additional smoothness
 - Eased Animations: Smooth easing functions for fade-out effects
 - Optimized Update Rates: Balanced update frequency for 30-60fps performance
 
// Smooth configuration example
WaveformController(
  maxDataPoints: 80,
  updateInterval: Duration(milliseconds: 33), // 30fps
  smoothingFactor: 0.85, // High smoothing
)
๐จ Design Inspiration #
This package is perfect for:
- ๐ค Voice recording apps
 - ๐ต Music players and visualizers
 - ๐ Voice chat applications
 - ๐๏ธ Podcast apps
 - ๐ Audio analysis tools
 - ๐ฎ Interactive audio games
 
๐ค Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
 - Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
 
๐ License #
This project is licensed under the MIT License - see the LICENSE file for details.
๐ API Documentation #
For detailed API documentation, visit pub.dev/documentation/waveform_visualizer
๐ Support #
If you find this package helpful, please:
- โญ Star it on GitHub
 - ๐ Like it on pub.dev
 - ๐ Report issues on the issue tracker
 
๐ Changelog #
See CHANGELOG.md for a list of changes in each version.
Made with โค๏ธ for the Flutter community