3.其他动画
Hero动画
Hero(
tag: path,
child:
Img....
)
Hero(
tage: path,
child:Img...
)
雪人雪花
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
List<Snowflake> _snowFlakes = List.generate(200, (index) => Snowflake());
AnimationController _controller;
int _count = 0;
_increment() {
setState(() {
this._count++;
});
}
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: Duration(seconds: 1),
vsync: this,
);
_controller.repeat();
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Container(
height: double.infinity,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.blue, Colors.lightBlue, Colors.white],
stops: [0.0, 0.7, 0.95])),
child: AnimatedBuilder(
animation: _controller,
builder: (_, __) {
_snowFlakes.forEach((snow) => snow.fall());
return CustomPaint(painter: MyPainter(_snowFlakes));
},
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
_controller.stop();
},
child: Icon(Icons.add),
));
}
}
class MyPainter extends CustomPainter {
List<Snowflake> _snowFlakes;
MyPainter(this._snowFlakes);
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()..color = Colors.white;
print(size);
canvas.drawCircle(size.center(Offset(0, 110)), 60.0, paint);
canvas.drawOval(
Rect.fromCenter(
center: size.center(Offset(0, 280)),
width: 200,
height: 250,
),
paint);
_snowFlakes.forEach((snowflake) {
canvas.drawCircle(
Offset(snowflake.x, snowflake.y), snowflake.radius, paint);
});
}
@override
bool shouldRepaint(MyPainter oldDelegate) => true;
}
class Snowflake {
double x = Random().nextDouble() * 400, y = Random().nextDouble() * 800;
double radius = Random().nextDouble() * 2 + 2;
double velocity = Random().nextDouble() * 4 + 2;
fall() {
y += velocity;
if (y > 800) {
y = 0;
x = Random().nextDouble() * 400;
radius = Random().nextDouble() * 2 + 2;
velocity = Random().nextDouble() * 4 + 2;
}
}
}
Flare/Rive动画引用
class _MyHomePageState extends State<MyHomePage> {
String _currentName = "day_idle";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: AnimatedContainer(
duration: Duration(seconds: 2),
color: this._currentName == "switch_day" || _currentName == "day_idle"
? Colors.white
: Colors.black,
child: GestureDetector(
onTap: () {
setState(() {
if (_currentName == "day_idle") {
_currentName = "switch_night";
} else if (_currentName == "night_idle") {
_currentName = "switch_day";
}
});
},
child: FlareActor("assets/switch day to night.flr",
alignment: Alignment.center,
fit: BoxFit.contain,
animation: _currentName, callback: (switchName) {
if (switchName == "switch_day") {
setState(() {
_currentName = "day_idle";
});
} else if (switchName == "switch_night") {
setState(() {
_currentName = "night_idle";
});
}
}),
),
)),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.add),
));
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】