Skip to content

Add clipRRect parameter to WaveStyle #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/src/audio_waveforms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class _AudioWaveformsState extends State<AudioWaveforms> {
shouldCalculateScrolledPosition:
widget.shouldCalculateScrolledPosition,
scaleFactor: widget.waveStyle.scaleFactor,
clipRRect: widget.waveStyle.clipRRect,
),
),
),
Expand Down
7 changes: 5 additions & 2 deletions lib/src/base/audio_waveforms_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ class AudioWaveformsInterface {

///platform call to get decibel
Future<double?> getDecibel() async {
var db = await _methodChannel.invokeMethod(Constants.getDecibel);
return db;
try {
return await _methodChannel.invokeMethod(Constants.getDecibel);
} catch (e) {
return 0;
}
}

///platform call to check microphone permission
Expand Down
4 changes: 4 additions & 0 deletions lib/src/base/wave_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class WaveStyle {
/// Value > 0 will be padded right and value < 0 will be padded left.
final double durationTextPadding;

/// Applies this clipRRect to waveforms.
final RRect? clipRRect;

/// Applies this gradient to waveforms.
///
/// **Use as below**
Expand Down Expand Up @@ -113,6 +116,7 @@ class WaveStyle {
this.durationLinesColor = Colors.blueAccent,
this.gradient,
this.scaleFactor = 20.0,
this.clipRRect,
}) : assert(waveThickness < spacing,
"waveThickness can't be greater than spacing");
}
7 changes: 7 additions & 0 deletions lib/src/painters/recorder_wave_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class RecorderWavePainter extends CustomPainter {
final Function(int) setCurrentPositionDuration;
final bool shouldCalculateScrolledPosition;
final double scaleFactor;
final RRect? clipRRect;

RecorderWavePainter({
required this.waveData,
Expand Down Expand Up @@ -82,6 +83,7 @@ class RecorderWavePainter extends CustomPainter {
required this.setCurrentPositionDuration,
required this.shouldCalculateScrolledPosition,
required this.scaleFactor,
this.clipRRect,
}) : _wavePaint = Paint()
..color = waveColor
..strokeWidth = waveThickness
Expand All @@ -103,6 +105,11 @@ class RecorderWavePainter extends CustomPainter {
pushBack();
revertClearlabelCall();
}

if (clipRRect != null) {
canvas.clipRRect(clipRRect!);
}

for (var i = 0; i < waveData.length; i++) {
///wave gradient
if (gradient != null) _waveGradient();
Expand Down