Skip to content
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;
}
Comment on lines +82 to +86

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change to getDecibel looks unrelated to the clipRRect feature — could it move to its own PR? Beyond scope, returning 0 in the catch is risky: the method returns Future<double?>, so 0 reads as a genuine decibel value and callers can't distinguish a real reading from a failure.

I'd let the PlatformException propagate, or return null to signal "no value", and log the error rather than discard it. The bound e is also unused (the analyzer flags unused_catch_clause) — catch (_) or on PlatformException catch would be cleaner.

}

///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;
Comment on lines +68 to +69

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposing this as a raw RRect means callers have to hardcode absolute LTRB coordinates and the box size, then recompute them whenever the layout or orientation changes. The idiomatic shape for a rounded-rect parameter is BorderRadius, which the painter can resolve against its own size on each paint and stay correct across devices. Could we take a BorderRadius here instead? The doc comment also just restates the field name — a line on what gets clipped, with a short example like gradient has, would help.


/// 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