flutter_touch_scale 1.5.0
flutter_touch_scale: ^1.5.0 copied to clipboard
This Flutter package delivers clear visual feedback through scale animations on user touch interactions.
Introduction #
This Flutter package delivers clear visual feedback through scale animations on user touch interactions.
See Also, If you want the change-log by version for this package. refer to Change Log for details.
Preview #
The gif image below may appear distorted and choppy due to compression.
Usage #
The following explains the basic usage of this package.
TouchScale(
onPress: () => print("Hello, World!"),
child: ... // <- this your widget
)
Use scale to choose whether the widget shrinks or expands while pressed.
TouchScale(
onPress: () => print("Pressed!"),
scale: 0.9, // shrink
child: ...
)
TouchScale(
onPress: () => print("Pressed!"),
scale: 1.1, // expand
child: ...
)
How to define the style globally. #
TouchScaleStyle defines the style of its descendant touch scale widgets, similar to how PrimaryScrollController defines the controller for its descendant widgets.
TouchScaleStyle(
scale: 1.1,
child: ...
)
Use TouchScaleResolver to customize how the scale value is resolved.
TouchScale(
scale: 0.9,
resolver: TouchScaleResolver.percent(),
onPress: () => print("Pressed!"),
child: ...
)
TouchScale(
scale: 8.0,
resolver: TouchScaleResolver.pixels(),
onPress: () => print("Pressed!"),
child: ...
)
TouchScale(
scale: 0.5,
resolver: TouchScaleResolver.stevens(),
onPress: () => print("Pressed!"),
child: ...
)
previewDuration delays the preview effect only while the gesture is still competing with another gesture. If there is no competing gesture, the touch feedback starts immediately.
Use rejectBehavior to define how pointer movement rejects the gesture. The default is TouchScaleRejectBehavior.leave.
TouchScale(
rejectBehavior: TouchScaleRejectBehavior.touchSlop,
onPress: () => print("Pressed!"),
child: ...
)
You can also apply the behavior to descendant widgets through TouchScaleStyle.
TouchScaleStyle(
rejectBehavior: TouchScaleRejectBehavior.none,
child: ...
)
The Properties of TouchScaleCallPhase #
The enumeration that defines the phase in which a touch scale callback is triggered.
| Name | Description |
|---|---|
| onAccepted | Sets the phase when the gesture is accepted, regardless of whether the animation starts. |
| onScaleDownEnd | Sets the phase when the scale-down animation has completed. |
| onScaleUpEnd | Sets the phase when the scale-up animation has completed. |
The Properties of TouchScaleRejectBehavior #
The enumeration that defines how a touch scale gesture is rejected based on pointer movement.
| Name | Description |
|---|---|
| none | Does not reject the gesture based on pointer movement. |
| touchSlop | Rejects the gesture when the pointer moves beyond the touch slop. |
| leave | Rejects the gesture when the pointer leaves the widget bounds. |