Skip to content
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

🐛 Fixed last wave flickering and minor docs update #197

Merged
merged 1 commit into from
Sep 29, 2023
Merged
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
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
34 changes: 28 additions & 6 deletions lib/src/audio_waveforms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ 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: _extraClipperHeight,
waveWidth: _waveWidth,
),
child: RepaintBoundary(
child: CustomPaint(
size: widget.size,
Expand Down Expand Up @@ -122,6 +120,30 @@ class _AudioWaveformsState extends State<AudioWaveforms> {
);
}

/// Gets width of a single wave including space between two waves.
double get _waveWidth =>
widget.waveStyle.waveThickness + widget.waveStyle.spacing;

/// Provides extra clipping if needed.
double get _extraClipperHeight {
if (widget.waveStyle.showDurationLabel) {
// If duration labels are enabled and for some reason labels are getting
// cut or effecting other widget cut. This will help to reduce or add
// clipping.
if (widget.waveStyle.extraClipperHeight != null) {
return widget.waveStyle.extraClipperHeight!;
}
// Default clipping. Calculated from duration line.
return widget.waveStyle.durationLinesHeight +
(widget.waveStyle.durationStyle.fontSize ??
widget.waveStyle.durationLinesHeight);
} else {
// If labels are disabled then there is no need to add/remove extra
// clipping.
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