搜索插件、代码仓与 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.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。