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

path_morph 封面
套件詳情v1.1.1

path_morph

此套件讓您建立路徑補間動畫。換句話說,它可讓一個路徑變形為另一個路徑。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
98
喜歡數
61
Pub 分數
150

安裝套件

flutter pub add path_morph

套件介紹

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

path_morph 是一個 Flutter 套件,可實現平滑的路徑補間動畫,讓開發者能夠將一個自訂路徑漸變到另一個路徑。它非常適合用於動畫中創建形狀或輪廓之間的流暢視覺過渡。此套件支援所有主要平台,並能與 Flutter 的動畫系統無縫整合。它透過隨時間插值兩個路徑的點來運作,為圖示、載入器或動態插圖等 UI 元素產生視覺上吸引人的效果。

適用情境

  • 建立動畫圖示過渡
  • 在UI中設計流體形狀變形
  • 動畫自定路徑圖形
  • 建構互動式載入指示器
  • 增強應用程式中的視覺敘事

主要特色

  • 平滑路徑插值
  • 跨平台支援
  • 路徑動畫的簡單 API
  • 與 Flutter 的 AnimationController 集成
  • 支援複雜的路徑幾何形狀

適合對象

  • 尋求動態視覺效果的UI/UX設計師
  • 開發人員建構動畫插圖
  • 需要自定路徑轉換的應用程式
  • 具有流暢動畫的互動式原型

使用建議

  • 效能可能會隨著高度複雜的路徑而有所變化
  • 需要仔細的路徑結構才能獲得良好結果
  • 最適合輕量級動畫
  • 不適合即時使用者繪製的路徑
  • 僅限無外部輸入的靜態路徑變形

原始 README

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

Path Morph

This is a pure Dart package that lets you smoothly morph one Flutter Path object into another. You can think of this as a path tween animation. The idea is to take two paths, a source path and a destination path, and smoothly move the points of the source path until it looks exactly like the destination path.

Usage

First you need to sample two paths using the PathMorph.samplePaths() method, which returns a SampledPathData object.

SampledPathData data = PathMorph.samplePaths(path1, path2);

Then you call the PathMorph.generateAnimations() method to create an animation for every point in the path. This method needs an AnimationController object and a SampledPathData object as arguments. Additionally, it expects you to pass a function to it, one that takes two arguments itself. In the body of the function, you must call setState() and update the value of the shiftedPoints list, which is present in the SampledPathData object.

AnimationController controller = AnimationController(vsync: this,
                                    duration: Duration(seconds: 1));

PathMorph.generateAnimations(controller, data, (i,z) {
    setState((){
      data.shiftedPoints[i] = z;
    });
});

Lastly, while rendering the morph animation, you can call the PathMorph.generatePath() method and pass the shiftedPoints list to it. This returns a Path object you can draw on your canvas. If you are using a CustomPainter object, you'll want to pass the path as an argument to it.

@override
Widget build(BuildContext context) {
    return CustomPaint(painter: MyPainter(PathMorph.generatePath(data)));
}

Do take a look at the example project to get a better idea.

Important

This package currently allows you to morph two paths only if they both have an equal number of contours. You can think of a contour as a line you can draw without lifting the pen. For example, the path to draw a triangle, a circle, or a square has one contour only. But a path to draw two concentric circles will have two contours.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。