swipable library

Swipable

Widget that can be animated in response to gestures, and calls event handlers with custom swipe/flick gestures are detected. Animations and gesture detection are parameterized.

Swipable is the only new Widget in this library, and accepts a child that can be animated with a Transform.scale, Transform.translate, Transform.rotate or Opacity as defined by user functions.

Animation

Animation tween functions receive a SwipableInfo containing:

  • position the current location of the pointer along the x-axis
  • startPosition the location of the pointer along the x-axis when the gesture was initiated
  • lastPosition the previous location of the pointer along the x-axis
  • contextWidth the width of the provided BuildContext, used to calculate fractional values
  • fractionalPosition the fraction of contextWidth represented by position
  • delta the difference between pointer and startPosition
  • fractionalDelta the fraction of contextWidth represented by delta
  • velocity the difference between pointer and lastPosition
  • fractionalVelocity the fraction of contextWidth represented by velocity

Tween functions should not modify the SwipableInfo state they consume, though this is still allowed for simpler code and to allow for advanced customization (especially with altering startPosition).

The tweenOpacity, tweenRotation, and tweenScale functions should yield doubles. The tweenTranslation function should yield an Offset.

Gesture Detection

The onSwipe and onFling event handler callback functions receive the SwipableInfo state and the DragEndDetails and yield a bool that can be used by onFling to cancel calling onSwipe if it yields false. These event handlers are typically used to alter the child parameter. Simply put, onFling will be called upon drag end if it meets the fling-related parameters, and onSwipe will be called on drag end unless onFling yields false.

  • maxFlingVelocity is the greatest (inclusive) velocity of the DragEndDetails that will result in the onFling event handler being called.
  • minFlingDistance is the smallest (inclusive) delta of the SwipableInfo that will result in the onFling event handler being called.
  • minFlingVelocity is the smallest (inclusive) velocity of the DragEndDetails that will result in the onFling event handler being called.

The onAction event handler callback is called on any drag event, and takes SwipableInfo state and drag event details. This is useful when extracting data out of the Swipable for example in gesture-dependent animations.

Classes

Swipable
Widget in Swipable library, detects gestures and calls event handlers.
SwipableInfo

Typedefs

SwipableCallbackFunction(SwipableInfo swipe, DragEndDetails event) → bool
SwipableTweenDoubleFunction(SwipableInfo swipe) → double
SwipableTweenOffsetFunction(SwipableInfo swipe) Offset