Flutter › Flutter Gestures & Touch Handling
How do you properly implement a custom swipeable card interface, such as the classic swipe left or swipe right pattern popularized by many dating apps, using Draggable or a raw GestureDetector combined with an AnimationController?
IntermediateAnswer
Implementing a genuinely custom swipeable card interface typically involves tracking the user's ongoing horizontal drag position using GestureDetector's onPanUpdate callback, visually moving the card in real time to directly follow the user's actual finger as they drag, and then, once the user genuinely releases their finger, using an AnimationController to either smoothly animate the card the rest of the way fully off screen if it was dragged sufficiently far in one particular direction, or otherwise to smoothly animate it back to its original resting starting position if the drag distance was not actually sufficient to trigger a genuine dismissal.
GestureDetector(
onPanUpdate: (details) => setState(() => offset += details.delta.dx),
onPanEnd: (details) => offset.abs() > 100 ? dismissCard() : resetCard(),
child: Transform.translate(offset: Offset(offset, 0), child: cardWidget),
)Real-world example A dating app style card swiping interface tracks a user's ongoing horizontal drag in real time, smoothly animating the current card entirely off screen once it has genuinely been dragged past a specific reasonable distance threshold, closely matching the exact familiar swipe interaction pattern users would already genuinely expect from similar popular apps.