一個 Flutter 套件,支援左右上下滑動的手勢,具有類似 Tinder 的卡片滑動功能。開發者可為每個滑動方向定義自訂邏輯,非常適合用於約會應用、產品展示或內容探索介面。此套件跨平台,可在 Android、iOS、Web、macOS、Windows 及 Linux 上順暢運作。提供流暢且可客製化的滑動體驗,內建動畫與手勢處理。
適用情境
約會應用介面
產品或商品發現
內容推薦系統
互動敘事
使用者偏好收集
主要特色
類似 Tinder 的滑動操作
每方向可自定義滑動邏輯
跨平台相容性
內建動畫
手勢識別
可擴展的控件設計
適合對象
開發基於滑動的使用者介面的開發者
需要用戶通過卡片滑動進行互動的應用程式
需要直覺導航模式的專案
原型設計互動式卡片體驗
使用建議
需要仔細處理滑動狀態管理
可能需要額外的樣式來處理複雜的佈局
大型數據集的性能影響
僅限基於卡片的互動
未針對垂直滾動列表進行優化
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
flutter_card_swiper
This is a Flutter package for a Tinder-like card swiper. ✨
It allows you to swipe left, right, up, and down and define your own business logic for each direction.
Very smooth animations supporting Android, iOS, Web & Desktop.
Why?
We built this package because we wanted to:
Have a fully customizable slider
Swipe in any direction
Undo swipes as many times as you want
Choose your own settings such as duration, angle, padding and more
Trigger swipes in any direction with the controller
Add callbacks while swiping, on end, or when the swiper is disabled
Detect the direction (left, right, top, bottom) the card was swiped
Show Cases
Swipe in any direction
Trigger swipes
Unswipe the cards
Fully customizable
Installation
Add this to your package's pubspec.yaml file:
card_swiper:...
OR run
flutterpubaddflutter_card_swiper
in your project's root directory.
Usage
You can place your CardSwiper inside of a Scaffold like we did here. Optional parameters can be defined to enable different features. See the following example:
Index of the first card when the swiper is initialized
false
isDisabled
false
Set to true if swiping should be disabled, has no impact when triggered from the outside
false
isLoop
true
Set to true if the stack should loop
false
maxAngle
30
Maximum angle that the card can reach during swiping
false
allowedSwipeDirection
AllowedSwipeDirection.all
Sets the direction in which the card can be swiped. It can be set to any combination of left, right up or down.
false
numberOfCardsDisplayed
2
Number of cards displayed at the same time
false
onEnd
-
Callback when there are no more cards left to swipe
false
onSwipe
-
Callback when the user swipes a card. If the function returns false, the swipe action is canceled. If it returns true, the swipe action is performed as expected
false
onTapDisabled
-
Callback when a card is tapped and isDisabled is true
false
onUndo
-
Callback when the controller calls undo. If the function returns false, the undo action is canceled. If it returns true, the undo action is performed as expected
A callback containing the horizontal and vertical swipe direction
false
showBackCardOnUndo
-
If true, the previous card will be shown in the background when swiping, and the swipe action will trigger an undo
false
undoSwipeThreshold
50
The horizontal swipe distance threshold, in pixels, after which the back card switches to the previous card. Only active when showBackCardOnUndo is true
false
undoDirection
UndoDirection.left
The direction of the swipe to trigger an undo
false
Controller
The Controller is used to swipe the card from outside of the widget. You can create a controller called CardSwiperController and save the instance for further usage. Please have a closer look at our Example for the usage.