From d4ded6de40eba974b64e37ea0421daa3ec43572b Mon Sep 17 00:00:00 2001 From: Szilard Date: Thu, 11 Jan 2024 21:36:58 +0100 Subject: [PATCH 1/3] add clipRRect support to recorder_wave_painter --- lib/src/audio_waveforms.dart | 1 + lib/src/base/wave_style.dart | 4 ++++ lib/src/painters/recorder_wave_painter.dart | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/lib/src/audio_waveforms.dart b/lib/src/audio_waveforms.dart index 52c2703e..c2998043 100644 --- a/lib/src/audio_waveforms.dart +++ b/lib/src/audio_waveforms.dart @@ -112,6 +112,7 @@ class _AudioWaveformsState extends State { shouldCalculateScrolledPosition: widget.shouldCalculateScrolledPosition, scaleFactor: widget.waveStyle.scaleFactor, + clipRRect: widget.waveStyle.clipRRect, ), ), ), diff --git a/lib/src/base/wave_style.dart b/lib/src/base/wave_style.dart index d4428912..9f0c864f 100644 --- a/lib/src/base/wave_style.dart +++ b/lib/src/base/wave_style.dart @@ -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** @@ -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"); } diff --git a/lib/src/painters/recorder_wave_painter.dart b/lib/src/painters/recorder_wave_painter.dart index de128c81..1eb6f9dc 100644 --- a/lib/src/painters/recorder_wave_painter.dart +++ b/lib/src/painters/recorder_wave_painter.dart @@ -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, @@ -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 @@ -131,6 +133,10 @@ class RecorderWavePainter extends CustomPainter { ///calculates scrolled position with respect to duration if (shouldCalculateScrolledPosition) _setScrolledDuration(size); + + if (clipRRect != null) { + canvas.clipRRect(clipRRect!); + } } @override From c32f815bfb911ace701066c47920e4b09247eccf Mon Sep 17 00:00:00 2001 From: Szilard Date: Thu, 11 Jan 2024 21:42:15 +0100 Subject: [PATCH 2/3] Update recorder_wave_painter.dart --- lib/src/painters/recorder_wave_painter.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/painters/recorder_wave_painter.dart b/lib/src/painters/recorder_wave_painter.dart index 1eb6f9dc..9c2dfe30 100644 --- a/lib/src/painters/recorder_wave_painter.dart +++ b/lib/src/painters/recorder_wave_painter.dart @@ -105,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(); @@ -133,10 +138,6 @@ class RecorderWavePainter extends CustomPainter { ///calculates scrolled position with respect to duration if (shouldCalculateScrolledPosition) _setScrolledDuration(size); - - if (clipRRect != null) { - canvas.clipRRect(clipRRect!); - } } @override From ee306a1a53de18e8c2f0d5c635b71da32be316be Mon Sep 17 00:00:00 2001 From: Szilard Date: Wed, 8 May 2024 15:42:06 +0200 Subject: [PATCH 3/3] Update audio_waveforms_interface.dart --- lib/src/base/audio_waveforms_interface.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/src/base/audio_waveforms_interface.dart b/lib/src/base/audio_waveforms_interface.dart index 085e00e2..abe0ad74 100644 --- a/lib/src/base/audio_waveforms_interface.dart +++ b/lib/src/base/audio_waveforms_interface.dart @@ -79,8 +79,11 @@ class AudioWaveformsInterface { ///platform call to get decibel Future 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