搜尋套件、儲存庫與 APP 分類

snap 封面
套件詳情v2.0.0

snap

一個功能強大的Flutter吸頂工具/組件,可實現非常靈活的吸頂管理以及在您的組件之間進行吸頂。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
42
喜歡數
21
Pub 分數
140

安裝套件

flutter pub add snap

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Snap 是一個全面的 Flutter 套件,為組件提供靈活的吸附功能,可在各種佈局中實現順暢且可自訂的吸附行為。它支援對吸附點、緩動動畫和動態調整的精確控制,非常適合建立回應式、手勢驅動的介面。此套件可與可捲動元件無縫整合,並提供對吸附位置和過渡效果的細緻管理。專為尋求進階手勢互動的開發者設計,Snap 能在基於網格或卡片式 UI 中提升使用者體驗。

適用情境

  • 建立可拖曳的卡片版面
  • 實現滑動到定位的導航
  • 建構響應式網格介面
  • 設計互動式滑塊
  • 啟用帶有吸附點的平滑捲動

主要特色

  • 靈活的快照點設定
  • 可自訂的動畫曲線
  • 支援多個吸附目標
  • 動態吸附調整
  • 手勢感知的吸附
  • 跨平台相容性

適合對象

  • 開發互動式 UI 的開發者
  • 實現基於手勢導航的設計人員
  • 需要精確組件對齊的應用程式
  • 使用可滾動網格或幻燈片的專案
  • 專注於精緻使用者互動的團隊

使用建議

  • 可能需要針對複雜佈局進行效能調校
  • 除了基本範例之外,文件內容有限
  • 管理多個快照狀態時可能出現的複雜性
  • 最適合中大型專案
  • 需要了解 Flutter 的觸控系統

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

snap

Cosmos Software Awesome Flutter

Pub License

An extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.

Inspired by WhatsApp's in-app Youtube player.

It is highly recommended to read the documentation and run the example project on a real device to fully understand and inspect the full range of capabilities.

Media | Description | How-to-Use

Notice

  • flick works as intended on actual devices even if it might appear to fail rarely on simulators. Don't be discouraged!

Recent

  • flick is now added. It is amazing! See Media for examples.

Media

Watch on Youtube:

v1.0.0 with Flick

v0.1.0



Description

This is an extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.

Just wrap your snapper widget with the SnapController widget, fill the parameters, define your snappable widget and this package will take care of everything else.

How-to-Use

"The view is what is being moved. It is the widget that snaps to the bound. The bound is what the view is being snapped to."

First, define two GlobalKeys- one for your view and one for your bound:

GlobalKey bound = GlobalKey();
GlobalKey view = GlobalKey();

Then, create a SnapController such as:

SnapController(
  uiChild(),                //uiChild
  false,                    //useCache
  view,                     //viewKey
  bound,                    //boundKey
  Offset.zero,              //constraintsMin
  const Offset(1.0, 1.0),   //constraintsMax
  const Offset(0.75, 0.75), //flexibilityMin
  const Offset(0.75, 0.75), //flexibilityMax
 {Key key,
  customBoundWidth  : 0,
  customBoundHeight : 0,
  snapTargets       : [
    const SnapTarget(Pivot.topLeft, Pivot.topLeft),
    const SnapTarget(Pivot.topRight, Pivot.topRight),
    const SnapTarget(Pivot.bottomLeft, Pivot.bottomLeft),
    const SnapTarget(Pivot.bottomRight, Pivot.bottomRight),
    const SnapTarget(Pivot.center, Pivot.center)
  ],
  animateSnap       : true,
  useFlick          : true,
  flickSensitivity  : 0.075,
  onMove            : _onMove,
  onDragStart       : _onDragStart,
  onDragUpdate      : _onDragUpdate,
  onDragEnd         : _onDragEnd,
  onSnap            : _onSnap})

Widget uiChild() {
  return Container(
    key: view,
    ...
  ); 
}

void _onMove(Offset offset);

void _onDragStart(dynamic dragDetails);
void _onDragUpdate(dynamic dragDetails);
void _onDragEnd(dynamic dragDetails);

void _onSnap(Offset offset);

Further Explanations:

For a complete set of descriptions for all parameters and methods, see the documentation.

  • Set [useCache] to true if your [uiChild] doesn't change during the Peek & Pop process.
  • Consider the following example:
Column(
  crossAxisAlignment: CrossAxisAlignment.start,
  children: [
    Expanded(
      child: Align(
        key: bound,
        alignment: const Alignment(-1.0, -1.0),
        child: SnapController(
          uiChild(),
          true,
          view,
          bound,
          Offset.zero,
          const Offset(1.0, 1.0),
          const Offset(0.75, 0.75),
          const Offset(0.75, 0.75),
          snapTargets: [
            const SnapTarget(Pivot.topLeft, Pivot.topLeft),
            const SnapTarget(Pivot.topRight, Pivot.topRight),
            const SnapTarget(Pivot.bottomLeft, Pivot.bottomLeft),
            const SnapTarget(Pivot.bottomRight, Pivot.bottomRight),
            const SnapTarget(Pivot.center, Pivot.center)
          ]
        )
      )
    )
  ]
)

In this excerpt, the bound is an Align widget which expands through a Column widget.

The SnapController is confined between Offset.zero and Offset(1.0, 1.0). This means the view will not exceed the limits of the bound.

The flexibility is confined between Offset(0.75, 0.75) and Offset(0.75, 0.75). This means that the view can be moved beyond the horizontal/vertical min/max constraints with a flexibility of 0.75 before it snaps.

The snapTargets determine from where and to where the view should snap once the movement is over. In this example:

  1. The top left corner of the view can snap to the top left corner of the bound.
  2. The top right corner of the view can snap to the top right corner of the bound.
  3. The bottom left corner of the view can snap to the bottom left corner of the bound.
  4. The bottom right corner of the view can snap to the bottom right corner of the bound.
  5. The center of the view can snap to the center of the bound.

Keep in mind that these constant values are provided only for the ease of use. snapTargets can consist of any values you wish.

  • Use [SnapControllerState]'s [bool isMoved(double treshold)] method to determine if the view is moved or not where [treshold] is the distance at which the view should be considered to be moved.

Notes

I started using and learning Flutter only some weeks ago so this package might have some parts that don't make sense, that should be completely different, that could be much better, etc. Please let me know! Nicely!

Any help, suggestion or criticism is appreciated!

Cheers.





所屬分類

依賴

依賴清單 1 項

  • flick^2.0.0

原始碼儲存庫

使用此套件的專案

暫無相關資料。