Skip to content

Commit

Permalink
🐛 Fixed last wave flickering and minor docs update
Browse files Browse the repository at this point in the history
Signed-off-by: vatsal tanna <vatsal.t@simformsolutions.com>
  • Loading branch information
Ujas-Majithiya authored and vatsaltanna-simformsolutions committed Aug 16, 2023
1 parent 9e724c9 commit d1f8972
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/src/audio_file_waveforms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ class _AudioFileWaveformsState extends State<AudioFileWaveforms>
onHorizontalDragEnd:
widget.enableSeekGesture ? (_) => _handleOnDragEnd() : null,
child: ClipPath(
// TODO: Remove static clipper when duration labels are added
clipper: WaveClipper(0),
// TODO: Update extraClipperHeight when duration labels are added
clipper: WaveClipper(extraClipperHeight: 0),
child: RepaintBoundary(
child: ValueListenableBuilder<int>(
builder: (_, __, ___) {
Expand Down
24 changes: 18 additions & 6 deletions lib/src/audio_waveforms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ class _AudioWaveformsState extends State<AudioWaveforms> {
onHorizontalDragStart:
widget.enableGesture ? _handleHorizontalDragStart : null,
child: ClipPath(
clipper: WaveClipper(!widget.waveStyle.showDurationLabel
? 0.0
: widget.waveStyle.extraClipperHeight ??
(widget.waveStyle.durationLinesHeight +
(widget.waveStyle.durationStyle.fontSize ??
widget.waveStyle.durationLinesHeight))),
clipper: WaveClipper(
extraClipperHeight: _getExtraClipperHeight(),
waveWidth:
widget.waveStyle.waveThickness + widget.waveStyle.spacing,
),
child: RepaintBoundary(
child: CustomPaint(
size: widget.size,
Expand Down Expand Up @@ -122,6 +121,19 @@ class _AudioWaveformsState extends State<AudioWaveforms> {
);
}

double _getExtraClipperHeight() {
if (widget.waveStyle.showDurationLabel) {
if (widget.waveStyle.extraClipperHeight != null) {
return widget.waveStyle.extraClipperHeight!;
}
return widget.waveStyle.durationLinesHeight +
(widget.waveStyle.durationStyle.fontSize ??
widget.waveStyle.durationLinesHeight);
} else {
return 0;
}
}

///This handles scrolling of the wave
void _handleHorizontalDragUpdate(DragUpdateDetails details) {
var direction = details.globalPosition.dx - _initialOffsetPosition;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/base/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum RecorderState { initialized, recording, paused, stopped }
/// Android and IOS are have been separated to better support
/// platform wise encoder and output formats.
///
/// Check https://developer.android.com/reference/android/media/MediaRecorder.AudioEncoder
/// Check [MediaRecorder.AudioEncoder](https://developer.android.com/reference/android/media/MediaRecorder.AudioEncoder)
/// for more info.
enum AndroidEncoder {
/// Default
Expand All @@ -44,7 +44,7 @@ enum AndroidEncoder {
/// Android and IOS are have been separated to better support
/// platform wise encoder and output formats.
///
/// Check https://developer.android.com/reference/android/media/MediaRecorder.OutputFormat
/// Check [MediaRecorder.OutputFormat](https://developer.android.com/reference/android/media/MediaRecorder.OutputFormat)
/// for more info.
enum AndroidOutputFormat {
/// Default
Expand Down Expand Up @@ -72,7 +72,7 @@ enum AndroidOutputFormat {
/// Android and IOS are have been separated to better support
/// platform wise encoder and output formats.
///
/// Check https://developer.apple.com/documentation/coreaudiotypes/1572096-audio_format_identifiers
/// Check [Audio Format Identifiers](https://developer.apple.com/documentation/coreaudiotypes/1572096-audio_format_identifiers)
/// for more info.
enum IosEncoder {
/// Default
Expand Down
10 changes: 7 additions & 3 deletions lib/src/base/wave_clipper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ import 'package:flutter/material.dart';
/// visible.
class WaveClipper extends CustomClipper<Path> {
final double extraClipperHeight;
final double waveWidth;

WaveClipper(this.extraClipperHeight);
WaveClipper({
required this.extraClipperHeight,
this.waveWidth = 0,
});

@override
getClip(Size size) {
final path = Path()
..lineTo(0, size.height + extraClipperHeight)
..lineTo(size.width, size.height + extraClipperHeight)
..lineTo(size.width, 0);
..lineTo(size.width - waveWidth, size.height + extraClipperHeight)
..lineTo(size.width - waveWidth, 0);
return path;
}

Expand Down

0 comments on commit d1f8972

Please sign in to comment.