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-axisstartPosition
the location of the pointer along the x-axis when the gesture was initiatedlastPosition
the previous location of the pointer along the x-axiscontextWidth
the width of the providedBuildContext
, used to calculate fractional valuesfractionalPosition
the fraction ofcontextWidth
represented byposition
delta
the difference betweenpointer
andstartPosition
fractionalDelta
the fraction ofcontextWidth
represented bydelta
velocity
the difference betweenpointer
andlastPosition
fractionalVelocity
the fraction ofcontextWidth
represented byvelocity
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 double
s. The tweenTranslation
function should yield an Offset
.
Gesture Detection
The onSwipe
and onFling
event handler callback functions receive the
SwipableInfo state 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 theDragEndDetails
that will result in theonFling
event handler being called.minFlingDistance
is the smallest (inclusive)delta
of the SwipableInfo that will result in theonFling
event handler being called.minFlingVelocity
is the smallest (inclusive)velocity
of theDragEndDetails
that will result in theonFling
event handler being called.
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