AnimationDirector 是一个 Flutter 包,旨在简化流畅且视觉上吸引人的动画创建。它提供了一种结构化的方法来管理复杂的动画序列,同时最大限度地减少样板代码。开发者可以使用直观的 API 定义和编排动画,从而更轻松地构建引人入胜的用户界面。该包专注于性能和开发体验,使 Flutter 应用中的过渡效果和动态效果更加流畅。
适合场景
创建交互式 UI 元素
构建动画引导屏幕
设计响应式按钮反馈
使用动态效果实现启动画面
动画列表项条目
通过流畅的过渡增强加载状态
主要特点
预定义动画预设
可链式调用的动画序列
状态之间的平滑插值
轻量且高效
与现有控件的轻松集成
对自定义缓动曲线的支持
适合对象
寻求快速动画实现的Flutter开发者
需要精致视觉反馈的应用程序
具有复杂动画工作流的项目
设计师与开发人员协作进行动态设计
注重一致动画模式的团队
使用建议
除了基本示例外,文档有限
无内置的平台特定行为支持
高级用法可能需要额外的学习
未针对极高频率动画进行优化
依赖外部依赖项以实现完整功能
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
animation_director
A package to create nice and smooth animations for flutter
Introduction
A simple package to build beautiful and smooth animations for flutter framework. By using this package, you don't need
to bother yourself with AnimationControllers, AnimationTweens and also timing and of those animations.
Here there are some simple examples of what I've made with this package in 5 minutes for each one.
The following descriptions may sounds complicated but it's pretty simple, sorry for my bad english, I think if you jump to
example directory and take a look at the codes, you'll find out it's really easy to use
ActorWidget
Each object on the screen is called an ActorWidget.
each ActorAction is an individual animation of the ActorWidget.
All ActorWidgets in your page run simultaneously.
All ActorActions inside of an ActorWidget run sequentially, but you can control how much it waits before starts the animation
using waitBeforeStart
List<String> group; // you can define one or multi group for action.Function onCompleted;
Function onStart;
Duration waitBeforeStart; // the amount of time the current action must wait to start, after the previous action is finishedActorPath path;
ActorPosition position;
ActorOpacity opacity;
ActorCharacter character;
ActorRotation rotation;
ActorScale scale;
if you want to animate some of your ActorWidgets, you can give a name to the actions of your actor. then start your AnimationDirector by that group.
Using this, only ActorWidgets which has the given group animate.
This is useful when you want to trigger an animation manually. see Example Menu3x3.
ActorCharacter
The actor character! your actor is represented by ActorCharacter.
ActorCharacter has the following properties:
Duration duration;
Curve curve;
double width;
double height;
Widget child;
String clipPath; // the string of the clip pathEdgeInsets padding;
EdgeInsets margin;
BoxDecoration decoration;
BoxDecoration foregroundDecoration;
Note: clipPath type is string! if follows svg codes rule. and for now only supports M, L, A, Q.
In order to generate a path you can use FlutterDev.site Path Creator.
Draw your path and copy The Result to the clipPath property
ActorPosition
You can animate the position of Actor using ActorPosition.
Duration duration;
Curve curve;
String path; // the String code of the pathint traversePercentage; // the percentage of `ActorCharacter` movement along the pathint startPositionInPercent; // the start position of animation in percentbool displayPath; // displays the path on the screen, bool displayProgress; // displays the progress of path filling on the screenOffset offset; // you can align the position of ActorCharacter widget on the pathPaint pathStyle; // style of the path linePaint progressStyle; // style of the progress lineint progressLength; // the length of progress line, the default is as equal as the pathint progressAnimationRepeat; // the repeat times of progress animationbool fadingProgress; // to make the tail of the progress line faded
Path Creator
In order to create paths easily head to FlutterDev.site Path Creator.
Draw your path and copy the generated code from The Result.
Adaptive Size
By default, the generated path is based on fixed numbers of your path and has the following effect
If you want to draw your path to be adaptive to the screen of any device, you need to select Adaptive Width
or Adaptive Height or both if you want your path to be fully adaptive.
When you select for example Adaptive Width, the drawing-area width will be considered as mobile,tablet,... width so you get following
effect with Adaptive Width. (500 for example)
But keep in mind, in both cases, the result may be different on different screen-sizes.
Example
Let's say we want to animate an orange circle from top-center of the screen to the center. Then after 2 seconds,
move the circle to the bottom of the page.
The first step is to create our character and position it to top of the page.