Animated Text Kit 是一个 Flutter 包,提供了一系列视觉上吸引人且可自定义的文本动画。它使开发者能够轻松地为其应用添加动态文本效果,例如打字、淡入淡出和滚动。适用于启动屏幕、欢迎消息或引人注目的用户界面元素,支持 Android、iOS、Web、macOS、Windows 和 Linux 多个平台。该包轻量级,与 Flutter 的 widget 系统无缝集成,只需最少的设置即可实现流畅的动画。
适合场景
启动画面
欢迎消息
交互式 UI 元素
加载指示器
动态标题
引导流程
主要特点
预构建的文本动画
可自定义的速度和延迟
对多平台的支持
与 Flutter 的轻松集成
平滑过渡
文本样式选项
适合对象
应用引导流程
吸引用户的界面
应用中的简单动画
教育类或演示类应用
创意数字展示
轻量级动画需求
使用建议
仅限文本动画
多个实例可能影响性能
不适合复杂的动画
需要仔细调整以获得最佳用户体验
适用于持续时间较短的特效
依赖于 Flutter 的渲染性能
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Animated Text Kit
A flutter package which contains a collection of some cool and awesome text animations. Recommended package for text animations in Codemagic's Ebook, "Flutter libraries we love". Try out our live example app.
pause – the time of the pause between animation texts
displayFullTextOnTap – tapping the animation will rush it to completion
isRepeatingAnimation – controls whether the animation repeats
repeatForever – controls whether the animation repeats forever
totalRepeatCount – number of times the animation should repeat (when repeatForever is false)
controller - It allows for control over the animation by providing methods to play, pause and reset the text animations programmatically
There are also custom callbacks:
onTap – This is called when a user taps the animated text
onNext(int index, bool isLast) – This is called before the next text animation, after the previous one's pause
onNextBeforePause(int index, bool isLast) – This is called before the next text animation, before the previous one's pause
onFinished - This is called at the end, when the parameter isRepeatingAnimation is set to false
Note: You might come up with an issue that the text does not get updated with setState as shown here. The solution to this, is a key that changes based on the text. For reference, watch this video.
New with Version 3
Version 3 refactored the code so that common animation controls were moved to
AnimatedTextKit and all animations, except for TextLiquidFill, extend from
AnimatedText. This saved hundreds of lines of duplicate code, increased
consistency across animations, and makes it easier to create new animations.
It also makes the animations more flexible because multiple animations may now
be easily combined. For example:
Using the legacy FadeAnimatedTextKit is equivalent to using AnimatedTextKit with FadeAnimatedText.
An advantage of AnimatedTextKit is that the animatedTexts may be any subclass of AnimatedText, while using FadeAnimatedTextKit essentially restricts you to using just FadeAnimatedText.
Legacy AnimatedTextKit classes
Have you noticed that animation classes come in pairs?
For example, there is FadeAnimatedText and FadeAnimatedTextKit.
The significant refactoring with Version 3 split the original FadeAnimatedTextKit into FadeAnimatedText and a re-usable AnimatedTextKit, then FadeAnimatedTextKit was adjusted for backwards compatibility.
When introducing a new AnimationText subclass, you may wonder if you also need to also introduce an additional Kit class. The answer is NO. :tada:
Going forward, we are championing the adoption of the Version 3 approach, and have deprecated the legacy Kit classes.
This will make creating new animations easier.
We know it makes some legacy code more verbose, but the flexibility and simplicity is a conscious trade-off.
returnSizedBox(
width: 250.0,
child: DefaultTextStyle(
style: constTextStyle(
fontSize: 30.0,
fontFamily: 'Bobbers',
),
child: AnimatedTextKit(
animatedTexts: [
TyperAnimatedText('It is not enough to do your best,'),
TyperAnimatedText('you must know what to do,'),
TyperAnimatedText('and then do your best'),
TyperAnimatedText('- W.Edwards Deming'),
],
onTap: () {
print("Tap Event");
},
),
),
);
Typewriter
returnSizedBox(
width: 250.0,
child: DefaultTextStyle(
style: constTextStyle(
fontSize: 30.0,
fontFamily: 'Agne',
),
child: AnimatedTextKit(
animatedTexts: [
TypewriterAnimatedText('Discipline is the best tool'),
TypewriterAnimatedText('Design first, then code'),
TypewriterAnimatedText('Do not patch bugs out, rewrite them'),
TypewriterAnimatedText('Do not test bugs out, design them out'),
],
onTap: () {
print("Tap Event");
},
),
),
);
You can easily create your own animations by creating new classes that extend
AnimatedText, just like most animations in this package. You will need to
implement:
Class constructor – Initializes animation parameters.
initAnimation – Initializes Animation instances and binds them to the given AnimationController.
animatedBuilder – Builder method to return a Widget based on Animation values.
completeText – Returns the Widget to display once the animation is complete. (The default implementation returns a styled Text widget.)
Then use AnimatedTextKit to display the custom animated text class like:
If you encounter any problems feel free to open an issue. If you feel the library is missing a feature, please raise a ticket on GitHub and I'll look into it. Pull request are also welcome.