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

add needed method onLongPress() #7

Open
wants to merge 1 commit into
base: main
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ and the Flutter guide for

- Truly simple and efficient.
- Customizable bouncing animation using `curve`, `scaleFactor` and `duration`.
- Options to control `onTap`, `onTapUp`, `onTapDown` and `onTapCancel`.
- Options to control `onTap`, `onTapUp`, `onTapDown`, `onTapCancel` and `onLongPress`.
- Enable and disable `onTap` option.
- Not sticky when scrolling.
- Does not trigger multiple `onTap` events when tapped on multiple `Bounceable` widget simultaneously.
Expand Down
14 changes: 12 additions & 2 deletions lib/src/bounceable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Bounceable extends StatefulWidget {
final void Function(TapUpDetails)? onTapUp;
final void Function(TapDownDetails)? onTapDown;
final VoidCallback? onTapCancel;
final VoidCallback? onLongPress;

/// The reverse duration of the scaling animation when `onTapUp`.
final Duration? duration;
Expand Down Expand Up @@ -34,6 +35,7 @@ class Bounceable extends StatefulWidget {
this.onTapUp,
this.onTapDown,
this.onTapCancel,
this.onLongPress,
this.duration = const Duration(milliseconds: 200),
this.reverseDuration = const Duration(milliseconds: 200),
this.curve = Curves.decelerate,
Expand All @@ -50,8 +52,7 @@ class Bounceable extends StatefulWidget {
_BounceableState createState() => _BounceableState();
}

class _BounceableState extends State<Bounceable>
with SingleTickerProviderStateMixin {
class _BounceableState extends State<Bounceable> with SingleTickerProviderStateMixin {
late final AnimationController _controller = AnimationController(
vsync: this,
duration: widget.duration,
Expand Down Expand Up @@ -86,6 +87,14 @@ class _BounceableState extends State<Bounceable>
});
}

void _onLongPress() {
if (widget.onLongPress != null) widget.onLongPress!();

_controller.reverse().then((_) {
_controller.forward();
});
}

void _onTapUp(TapUpDetails details) {
if (widget.onTapUp != null) widget.onTapUp!(details);
_controller.forward();
Expand All @@ -111,6 +120,7 @@ class _BounceableState extends State<Bounceable>
onTapDown: widget.onTap != null ? _onTapDown : null,
onTapUp: widget.onTap != null ? _onTapUp : null,
onTap: widget.onTap != null ? _onTap : null,
onLongPress: widget.onLongPress != null ? _onLongPress : null,
child: ScaleTransition(
scale: _animation,
child: widget.child,
Expand Down