flutter_touch_ripple 2.7.2

SDKflutter
Platformandroidioswindowslinuxmacos

This flutter package is customizable touch ripple effect widget for flutter, very flexible and performant, providing smooth touch effect animations.

Introduction

This Flutter package allows developer to customize most of the behaviors and animations, with excellent performance and a touch effect package that can be controlled externally.

See Also, If you want to watch the tutorial video for that package. click to this, If you want the change-log by version for this package. refer to Change Log for details.

Event TypeDescription♾️ Async♻️ Consecutive
TapWhen the user taps or clicks.🟢🔴
Double TapWhen the user double taps or double clicks.🔴🟢
Long TapWhen the user long tap or long press.🔴🟢
Drag HorizontalWhen the user dragging to left or right.🟡🟡
Drag VerticalWhen the user dragging to top or bottom.🟡🟡

Preview

The gif image below may appear distorted and choppy due to compression.

preview

Usage

The following explains the basic usage of this package.

How to apply the ripple effect?

Called when the user taps or clicks.

TouchRipple(
  onTap: () => print("Hello, World!"),
  child: ... // <- this your widget
)

How to perform an async task?

TouchRipple<String>(
    onTapAsync: () async {
        return await Future.delayed(const Duration(milliseconds: 500), () {
            return "end";
        });
    },
    onTapAsyncStart: () => print("start"),
    onTapAsyncEnd: print,
    // ... skip
);

How to define the style globally.

TouchRippleStyle defines the style of its descendant touch ripple widgets, similar to how PrimaryScrollController defines the controller for its descendant widgets.

TouchRippleStyle(
  rippleColor: Colors.blue.withAlpha(50),
  rippleBorderRadius: BorderRadius.circular(10),
  overlapBehavior: TouchRippleOverlapBehavior.ignore,
  cancelBehavior: TouchRippleCancelBehavior.none,
  onlyMainButton: false,
  tapBehavior: TouchRippleBehavior(...),
  child: ...
),

The Properties of TouchRipple

NameDescriptionType
onTapThe callback function is called when the user taps or clicks.VoidCallback?
onTapAsyncThe callback function is called when the user taps or clicks. but this function ensures that the touch ripple effect remains visible until the asynchronous operation is completed and prevents additional events during that time.TouchRippleAsyncCallback<T>?
onTapAsyncStartThe callback function is called when an asynchronous operation is initiated by a tap. It provides the associated Future instance for the ongoing operation.TouchRippleAsyncNotifyCallback<T>?
onTapAsyncEndThe callback function is called when the result of the asynchronous operation is ready. It allows handling the result once the operation is complete.TouchRippleAsyncResultCallback<T>?
onDoubleTapThe callback function is called when the user double taps or double clicks.VoidCallback?
onDoubleTapConsecutiveThe callback function is called to determine whether consecutive double taps should continue. It returns a [bool] indicating whether the long tap event should continue after the initial occurrence.TouchRippleContinuableCallback?
onDoubleTapStartThe callback function is a lifecycle callback for the double-tap event. It is called when a double tap starts, which is useful for handling actions that occur during successive double taps.VoidCallback?
onDoubleTapEndThe callback function is a lifecycle callback for the double-tap event. It is called when a double tap ends, providing the advantage of knowing when a series of consecutive double taps has finished.VoidCallback?
onLongTapThe callback function is called when the user long presses or long clicks.TouchRippleContinuableCallback?
onLongTapStartThe callback function is a lifecycle callback for the long-tap event. It is called when a long tap starts, which is useful for initiating actions that require a sustained press.VoidCallback?
onLongTapEndThe callback function is a lifecycle callback for the long-tap event. It is called when a long tap ends, providing the advantage of knowing when a series of consecutive long taps has concluded.VoidCallback?
onDragHorizontalThe callback function is called when the user dragging to left or right.TouchRippleDragCallback?
onDragHorizontalStartThe callback function is a lifecycle callback for the horizontal drag event. It is called when a horizontal drag starts, which is useful for handling actions that occur at the beginning of the drag.VoidCallback?
onDragHorizontalEndThe callback function is a lifecycle callback for the horizontal drag event. It is called when a horizontal drag ends, providing the advantage of knowing when the drag interaction has finished.VoidCallback?
onDragVerticalThe callback function is called when the user dragging to top or bottom.TouchRippleDragCallback?
onDragVerticalStartThe callback function is a lifecycle callback for the vertical drag event. It is called when a vertical drag starts, which is useful for handling actions that occur at the beginning of the drag.VoidCallback?
onDragVerticalEndThe callback function is a lifecycle callback for the vertical drag event. It is called when a vertical drag ends, providing the advantage of knowing when the drag interaction has finished.VoidCallback?
onFocusStartThe callback function is a lifecycle callback for focus touch ripple events. It is called when a focus touch event starts, allowing for the initiation of actions based on the beginning of the focus event sequence.VoidCallback?
onFocusEndThe callback function is a lifecycle callback for focus touch ripple events. It is called when a focus touch event ends, providing the advantage of knowing when a series of focus touch ripple events has concluded.VoidCallback?
onHoverStartThe callback function called when the cursor begins hovering over the widget. (by [MouseRegion]) This function allows for the initiation of actions based on the hover interaction. This function is not called in touch-based environments yet.VoidCallback?
onHoverEndThe callback function called when the cursor begins to leave the widget. (by [MouseRegion]) This function allows for actions to be executed based on the end of the hover interaction. This function is not called in touch-based environments yet.VoidCallback?
hitBehaviorThe behavior of hit testing for the child widget.HitTestBehavior?
rippleColorThe background color of a spread ripple effect.Color?
hoverColorThe background color of a effect when the user hovers.Color?
focusColorThe background color of the solid effect when a consecutive (e.g. about double-tap and long-tap) event state occurs.Color?
rippleScaleThe scale percentage value of a ripple effect and by default the origin position is center.double?
ripplePaddingThe value of the padding of the ripple effect. In other words, it defines how much larger it can be to the outside than its the intrinsic size.double?
rippleBlurThe radius of a blur filter for spread ripple effect. It cannot be negative and as the value increases, the edge of the spread ripple effect becomes blurrier.TouchRippleBlur?
sparkleRippleBlurThe blur radius for the sparkle ripple effect. Android 12 uses 1.0 as the default, while this package uses 0.5.double?
rippleBorderRadiusThe instance of a border radius for a ripple effect. For reference, this option can be replaced with a widget like [ClipRRect] depending on the situation.BorderRadius?
previewDurationThe duration for which the ripple effect is previewed even if the gesture is not finalized, allowing the user to see the effect while the pointer is down or moving.Duration?
tappableDurationThe duration after which the gesture is considered rejected if the pointer is still down and no tap is completed. If this duration elapses without a successful gesture, the gesture will be rejected.Duration?
doubleTappableDurationThe minimum duration used to distinguish between a tap and a double-tap. If the user does not perform a second tap within this duration, it is considered just a single-tap.Duration?
doubleTapAliveDurationThe duration until double-tap deactivation. During this period, any single tap is still considered a double-tap without requiring continuous double-tapping.Duration?
longTappableDurationThe minimum duration used to distinguish between a tap and a long-tap. After this duration has passed, the long-tap effect starts to be displayed to the user.Duration?
longTapCycleDurationThe duration until long-tap reactivation. After this period, any pointer down and move is still considered a long-tap without requiring the continuous process of pointer-up followed by pointer-down.Duration?
tapBehaviorThe touch ripple behavior applied to the touch ripple effect for tapped or clicked.TouchRippleBehavior?
doubleTapBehaviorThe touch ripple behavior applied to the touch ripple effect for double tapped or double clicked.TouchRippleBehavior?
longTapBehaviorThe touch ripple behavior applied to the touch ripple effect for long tapped or long pressed and long clicked.TouchRippleBehavior?
dragBehaviorThe touch ripple behavior applied to the touch ripple effect for the horizontal dragging or the vertical dragging.TouchRippleBehavior?
rejectBehaviorThe behavior that defines when a gesture should be rejected, specifying the conditions for rejection.TouchRippleRejectBehavior?
cancelBehaviorThe behavior that defines the touch ripple spread animation when the touch ripple effect is canceled.TouchRippleCancelBehavior?
overlapBehaviorThe behavior of a touch ripple when it overlaps with other ripple effects. (e.g. overlappable, cancel, ignore)TouchRippleOverlapBehavior?
renderOrderTypeThe enumeration specifies the rendering order of the touch ripple effect, determining whether it should appear in the foreground or background.TouchRippleRenderOrderType?
focusTimingThe enumeration defines when the focus of a touch ripple should start, specifying the priority based on timing conditions.TouchRippleFocusTiming?
originThe enumeration defines the starting point of a spread ripple effect, specifying the origin of the ripple based on the user interaction.TouchRippleOrigin?
shapeThe enumeration defines the shape of the ripple effect based on the widget layout, specifying how the ripple appears visually.TouchRippleShape?
hoverAnimationThe instance of the fade animation for the touch ripple effect when the hover effect is triggered.TouchRippleAnimation?
focusAnimationThe instance of the fade animation for the touch ripple effect when the focus effect is triggered.TouchRippleAnimation?
onlyMainButtonThe boolean that is whether only the main button is recognized as a gesture when the user that is using mouse device clicks on the widget.bool?
useHoverEffectWhether the hover effect is enabled for touch ripple animations. If true, a solid hover effect is applied when the user hovers.bool?
useFocusEffectWhether the focus effect is enabled for touch ripple animations. If true, a solid focus color effect is applied for consecutive events like double-tap and long-tap or others.bool?
useSparkleShaderWhether using the Material ink sparkle for touch ripple effect. Refer related to [InkSparkle] class to details.bool?
controllerThe controller defines and manages states, listeners, a context and other values related to touch ripple, ensuring that each state exists uniquely within the controller.TouchRippleController?
childThe widget that is target to apply touch ripple related effects.Widget

The Properties of TouchRippleRejectBehavior

The enumeration defines when a gesture should be rejected, specifying the conditions for rejection.

NameDescription
noneSets the gesture to not be rejected regardless of any action or event. However, if the gesture is forcibly rejected due to a scroll gesture, the rejection will occur as expected.
touchSlopSets the gesture to be canceled if the pointer movement distance is greater than or equal to [kTouchSlop].
leaveSets the gesture to be canceled if the pointer position is outside the area occupied by the widget.

When TouchRippleRejectBehavior.none

none

When TouchRippleRejectBehavior.touchSlop

touchSlop

When TouchRippleRejectBehavior.leave

leave

The Properties of TouchRippleOverlapBehavior

The enumeration defines the behavior of a touch ripple when it overlaps with other ripple effects.

NameDescription
overlappableSets the touch ripples to be allowed to overlap with each other.
cancelSets the touch ripple to be canceled if the effects overlap, with the new effect being added to the stack.
ignoreSets the event to be ignored if the effects overlap, canceling the previous touch effect until it disappears.

When TouchRippleOverlapBehavior.overlappable

overlappable

When TouchRippleOverlapBehavior.cancel

cancel

When TouchRippleOverlapBehavior.ignore

ignore

The Properties of TouchRippleCancelBehavior

The enumeration defines the behavior that defines the touch ripple spread animation when the touch ripple effect is canceled.

NameDescription
noneSets the behavior to perform no action when the effect is canceled.
stopSets the behavior to stop the spread animation of the touch ripple effect when the effect is canceled.
reverseSets the behavior to reverse the spread animation of the touch ripple effect when the effect is canceled.

When TouchRippleCancelBehavior.none

none

When TouchRippleCancelBehavior.stop

stop

When TouchRippleCancelBehavior.reverse

reverse

The Properties of TouchRippleFocusTiming

The enumeration defines when the focus of a touch ripple should start, specifying the priority based on timing conditions.

NameDescription
rejectableSets the focus event to start when the ripple is in a rejectable state, meaning the gesture has not yet been fully accepted, but the effect is visible and can be canceled.
consecutiveSets the focus event to start when multiple ripple effects occur in rapid succession. This setting prevents the focus from being triggered prematurely when in a rejectable state.

When TouchRippleFocusTiming.rejectable

rejectable

When TouchRippleFocusTiming.consecutive

consecutive

The Properties of TouchRippleOrigin

The enumeration defines the starting point of a spread ripple effect, specifying the origin of the ripple based on the user interaction.

NameDescription
pointer_downSets the effect to originate from the point where the pointer-down.
pointer_moveSets the effect to originate from the point where the pointer-move.
centerSets the effect to originate from the center of the widget, regardless of the pointer's position.

When TouchRippleOrigin.pointer_down

pointer_down

When TouchRippleOrigin.pointer_move

pointer_move

When TouchRippleOrigin.center

center

The Properties of TouchRippleShape

The enumeration defines the shape of the ripple effect based on the widget layout, specifying how the ripple appears visually.

NameDescription
normalSets the shape to a square that corresponds to the area occupied by the widget layout.
inner_circleSets the shape to a circle that remains within the bounds of the widget layout.
outer_circleSets the shape to a circle that extends beyond the bounds of the widget layout.

When TouchRippleShape.normal

normal

When TouchRippleShape.inner_circle

inner_circle

When TouchRippleShape.outer_circle

outer_circle

The Properties of TouchRippleRenderOrderType

The enumeration specifies the rendering order of the touch ripple effect, determining whether it should appear in the foreground or background.

NameDescription
foregroundSets the behavior to draw the touch ripple in the foreground, meaning it will appear above all other visual widgets in the interface.
backgroundSets the behavior to draw the touch ripple in the background, ensuring it appears beneath all other visual widgets in the interface.

When TouchRippleRenderOrderType.foreground

foreground

When TouchRippleRenderOrderType.background

background