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

Added onTapDown #50

Open
wants to merge 1 commit into
base: master
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
92 changes: 62 additions & 30 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ packages:
dependency: transitive
description:
name: async
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.10.0"
version: "2.11.0"
audioplayers:
dependency: "direct main"
description:
Expand All @@ -29,10 +29,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
version: "1.3.0"
clock:
dependency: transitive
description:
Expand All @@ -45,10 +45,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.0"
version: "1.18.0"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -97,8 +97,8 @@ packages:
flutter_audio_waveforms:
dependency: "direct main"
description:
path: "/Users/rutviktak/flutter_projects/flutter_plugins/flutter_audio_waveforms/"
relative: false
path: ".."
relative: true
source: path
version: "1.2.1+8"
flutter_lints:
Expand Down Expand Up @@ -135,14 +135,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.1"
js:
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
url: "https://pub.dev"
source: hosted
version: "10.0.4"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
url: "https://pub.dev"
source: hosted
version: "3.0.3"
leak_tracker_testing:
dependency: transitive
description:
name: js
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "0.6.5"
version: "3.0.1"
lints:
dependency: transitive
description:
Expand All @@ -155,34 +171,34 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.13"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
version: "1.12.0"
path:
dependency: transitive
description:
name: path
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.2"
version: "1.9.0"
path_provider:
dependency: transitive
description:
Expand Down Expand Up @@ -272,26 +288,26 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand All @@ -312,10 +328,18 @@ packages:
dependency: transitive
description:
name: test_api
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
touchable:
dependency: transitive
description:
name: touchable
sha256: "50040b39778bb1adc8a480625de8681253bd2134785395cf16abd66bb13d3ed0"
url: "https://pub.dev"
source: hosted
version: "0.4.16"
version: "1.0.2"
typed_data:
dependency: transitive
description:
Expand All @@ -340,6 +364,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
url: "https://pub.dev"
source: hosted
version: "14.2.1"
win32:
dependency: transitive
description:
Expand All @@ -357,5 +389,5 @@ packages:
source: hosted
version: "0.2.0+1"
sdks:
dart: ">=2.18.0 <3.0.0"
flutter: ">=2.8.0"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies:
sdk: flutter

flutter_audio_waveforms:
path: /Users/rutviktak/flutter_projects/flutter_plugins/flutter_audio_waveforms/ # 1.0.0+1
path: ../ # 1.0.0+1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
Expand Down
16 changes: 16 additions & 0 deletions lib/src/core/audio_waveform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ abstract class AudioWaveform extends StatefulWidget {
required this.showActiveWaveform,
this.absolute = false,
this.invert = false,
this.onTapDown,
}) : assert(
debugMaxandElapsedDuration(
maxDuration,
Expand Down Expand Up @@ -94,6 +95,8 @@ abstract class AudioWaveform extends StatefulWidget {
/// Whether to show the active waveform or not.
final bool showActiveWaveform;

final Function(Duration duration)? onTapDown;

/// Alignment of the waveform in the canvas.
@protected
final WaveformAlignment waveformAlignment;
Expand Down Expand Up @@ -277,4 +280,17 @@ abstract class AudioWaveformState<T extends AudioWaveform> extends State<T> {
_updateActiveSamples();
}
}

void onTapDown(TapDownDetails details) {
final dx = details.localPosition.dx;
final index = (dx / sampleWidth).round();

final ratio = index / widget.samples.length;

final duration = Duration(
milliseconds: (ratio * maxDuration!.inMilliseconds).round(),
);

widget.onTapDown?.call(duration);
}
}
12 changes: 12 additions & 0 deletions lib/src/core/waveform_painters_ab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ abstract class ActiveWaveformPainter extends WaveformPainter {
PaintingStyle style = PaintingStyle.stroke,
this.borderWidth = 0.0,
this.borderColor = opaqueBlack,
required this.context,
this.onTapDown,
}) : super(
samples: [], //samples,
color: color,
Expand All @@ -76,6 +78,10 @@ abstract class ActiveWaveformPainter extends WaveformPainter {
/// Stroke/Border Width
final Color borderColor;

final BuildContext context;

final Function(TapDownDetails details)? onTapDown;

/// Get shoudlRepaintValue
bool getShouldRepaintValue(covariant ActiveWaveformPainter oldDelegate) {
return !checkforSamplesEquality(activeSamples, oldDelegate.activeSamples) ||
Expand Down Expand Up @@ -157,6 +163,8 @@ abstract class ActiveInActiveWaveformPainter extends WaveformPainter {
required WaveformAlignment waveformAlignment,
PaintingStyle style = PaintingStyle.stroke,
required this.strokeWidth,
required this.context,
this.onTapDown,
}) : super(
samples: samples,
color: inactiveColor,
Expand All @@ -178,6 +186,10 @@ abstract class ActiveInActiveWaveformPainter extends WaveformPainter {
/// Stroke Width
final double strokeWidth;

final BuildContext context;

final Function(TapDownDetails details)? onTapDown;

/// Get shoudlRepaintValue
bool getShouldRepaintValue(
covariant ActiveInActiveWaveformPainter oldDelegate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_audio_waveforms/src/core/waveform_painters_ab.dart';
import 'package:flutter_audio_waveforms/src/util/waveform_alignment.dart';
import 'package:flutter_audio_waveforms/src/waveforms/polygon_waveform/polygon_waveform.dart';
import 'package:touchable/touchable.dart';

///InActiveWaveformPainter for the [PolygonWaveform]
class CurvedPolygonActiveInActiveWaveformPainter
Expand All @@ -16,6 +17,8 @@ class CurvedPolygonActiveInActiveWaveformPainter
required super.activeColor,
required super.strokeWidth,
required super.style,
required super.context,
super.onTapDown,
});

@override
Expand Down Expand Up @@ -80,5 +83,15 @@ class CurvedPolygonActiveInActiveWaveformPainter
final shiftedPath = path.shift(Offset(0, alignPosition));

canvas.drawPath(shiftedPath, paint);

TouchyCanvas(context, canvas).drawRect(
Rect.fromCenter(
center: size.center(Offset.zero),
width: size.width,
height: size.height,
),
Paint()..color = Colors.transparent,
onTapDown: onTapDown,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_audio_waveforms/src/core/audio_waveform.dart';
import 'package:flutter_audio_waveforms/src/core/waveform_painters_ab.dart';
import 'package:flutter_audio_waveforms/src/waveforms/curved_polygon_waveform/active_inactive_waveform_painter.dart';
import 'package:touchable/touchable.dart';

/// [CurvedPolygonWaveform] paints a squiggly waveform.
/// The painter for this waveform is of the type [ActiveInActiveWaveformPainter]
Expand Down Expand Up @@ -34,6 +35,7 @@ class CurvedPolygonWaveform extends AudioWaveform {
super.showActiveWaveform = true,
super.absolute = false,
super.invert = false,
super.onTapDown,
}) : assert(strokeWidth >= 0, "strokeWidth can't be negative.");

/// The color of the active portion of the waveform.
Expand Down Expand Up @@ -63,18 +65,23 @@ class _SquigglyWaveformState extends AudioWaveformState<CurvedPolygonWaveform> {
final activeRatio = this.activeRatio;
final waveformAlignment = this.waveformAlignment;

return CustomPaint(
size: Size(widget.width, widget.height),
isComplex: true,
painter: CurvedPolygonActiveInActiveWaveformPainter(
samples: processedSamples,
activeColor: widget.activeColor,
inactiveColor: widget.inactiveColor,
activeRatio: activeRatio,
waveformAlignment: waveformAlignment,
strokeWidth: widget.strokeWidth,
sampleWidth: sampleWidth,
style: widget.style,
return CanvasTouchDetector(
gesturesToOverride: const [GestureType.onTapDown],
builder: (context) => CustomPaint(
size: Size(widget.width, widget.height),
isComplex: true,
painter: CurvedPolygonActiveInActiveWaveformPainter(
samples: processedSamples,
activeColor: widget.activeColor,
inactiveColor: widget.inactiveColor,
activeRatio: activeRatio,
waveformAlignment: waveformAlignment,
strokeWidth: widget.strokeWidth,
sampleWidth: sampleWidth,
style: widget.style,
context: context,
onTapDown: onTapDown,
),
),
);
}
Expand Down
Loading