Bounceable
A Flutter widget that provides smooth, customizable bounce animation effects on tap. Features iOS-like Cupertino motion physics for natural, delightful interactions.
Features
- Simple API - Just wrap any widget with
Bounceable - Smooth animations - Uses Cupertino motion physics for iOS-like feel
- Customizable - Adjust scale, enable/disable haptics, custom callbacks
- Long press support - Built-in handling for long press gestures
- Haptic feedback - Optional haptic feedback on long press
- Performant - Minimal overhead with optimized animation handling
Installation
Add bounceable to your pubspec.yaml:
dependencies:
bounceable: ^1.0.0
Then run:
flutter pub get
Usage
Basic Usage
import 'package:bounceable/bounceable.dart';
Bounceable(
onTap: () => print('Tapped!'),
child: Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(12),
),
child: Text('Tap me!'),
),
)
With Long Press
Bounceable(
onTap: () => print('Tapped!'),
onLongPress: () => print('Long pressed!'),
child: YourWidget(),
)
Shrink Effect (Instead of Grow)
By default, the widget grows slightly when pressed. To create a shrink effect instead:
Bounceable(
scaleFactorOnTap: 0.95, // Values < 1 create a shrink effect
onTap: () => print('Tapped!'),
child: YourWidget(),
)
Disable Haptic Feedback
Bounceable(
enableHapticFeedback: false,
onLongPress: () => print('No haptic!'),
child: YourWidget(),
)
Custom Scale Factor
Bounceable(
scaleFactorOnTap: 1.15, // 15% larger on press
onTap: () => print('Big bounce!'),
child: YourWidget(),
)
API Reference
Bounceable
| Parameter | Type | Default | Description |
|---|---|---|---|
child |
Widget |
required | The widget to wrap with the bounce effect |
onTap |
VoidCallback? |
null |
Called when the widget is tapped |
onLongPress |
VoidCallback? |
null |
Called when the widget is long pressed |
onLongPressStart |
VoidCallback? |
null |
Called when a long press gesture starts |
onTapUp |
Function(TapUpDetails)? |
null |
Called when the user releases after a tap |
onTapDown |
Function(TapDownDetails)? |
null |
Called when the user starts a tap |
onTapCancel |
VoidCallback? |
null |
Called when a tap is cancelled |
scaleFactorOnTap |
double |
1.075 |
The scale multiplier when pressed |
hitTestBehavior |
HitTestBehavior? |
opaque |
How to behave during hit testing |
enableHapticFeedback |
bool |
true |
Whether to provide haptic feedback on long press |
Scale Factor Values
> 1.0- Widget grows when pressed (e.g.,1.075= 7.5% larger)< 1.0- Widget shrinks when pressed (e.g.,0.95= 5% smaller)= 1.0- No scale change (not recommended)
Performance Considerations
- Efficient animation - Uses
SingleTickerProviderStateMixinfor optimal performance - Proper disposal - Animation controller is correctly disposed when the widget is removed
- Optimized rebuilds - Uses
AnimatedBuilderso only the transform rebuilds, not the child widget - Lightweight - Minimal overhead added to your widget tree
Dependencies
This package uses the motor package for smooth iOS-like spring animations.
Example
Check out the example directory for a complete sample app demonstrating all features.
License
MIT License - see the LICENSE file for details.
Author
Created by Luca Kramberger
Libraries
- bounceable
- A Flutter widget that provides smooth bounce animation effects.