
【自学Flutter】32 交错动画的使用
发布日期:2021-05-12 19:48:55
浏览次数:13
分类:精选文章
本文共 3895 字,大约阅读时间需要 12 分钟。
���������������������
1. ���������
import 'package:flutter/material.dart';void main() => runApp(MyApp());class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState();}class _MyAppState extends Statewith TickerProviderStateMixin { AnimationController controller; @override void initState() { super.initState(); controller = AnimationController( duration: const Duration(milliseconds: 2000), vsync: this, ); } Future playAnimation() async { await controller.forward().orCancel; await controller.reverse().orCancel; } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { playAnimation(); }, child: Center( child: Container( width: 300.0, height: 300.0, decoration: BoxDecoration( color: Colors.black.withOpacity(0.1), border: Border.all( color: Colors.black.withOpacity(0.5), ), ), child: StaggerAnimation( controller: controller, ), ), ), ), ), ); }}class StaggerAnimation extends StatelessWidget { final Animation controller; Animation height; Animation padding; Animation color; StaggerAnimation({Key key, this.controller}) : super(key: key) { height = Tween ( begin: 0, end: 300.0, ).animate(CurvedAnimation( parent: controller, curve: Interval(0.0, 0.6, curve: Curves.ease), )); color = ColorTween( begin: Colors.green, end: Colors.red, ).animate(CurvedAnimation( parent: controller, curve: Interval(0.0, 0.6, curve: Curves.ease), )); padding = Tween ( begin: EdgeInsets.only(left: 0.0), end: EdgeInsets.only(left: 300), ).animate(CurvedAnimation( parent: controller, curve: Interval(0.6, 1.0, curve: Curves.ease), )); } @override Widget build(BuildContext context) { return AnimatedBuilder( builder: (context, child) { return Container( alignment: Alignment.bottomLeft, padding: padding.value, child: Container( color: color.value, width: 30.0, height: height.value, ), ); }, animation: controller, ); }}
2. ���������������
������������������������������Flutter������������������������������������������������������������������������������
MyApp
���������������������������������������������GestureDetector
������������������������AnimationController
������������������������������������������������2000������������vsync
���������playAnimation
������������������������������������������������������������������������������StaggerAnimation
���������������������StatelessWidget
������������������������������- ���������������������Singleton������������
Psuedo_resolve
���������������������Animation
��������� - ������
Tween
���CurvedAnimation
��������������������������������������������������������������� - ���
build
������������������AnimatedBuilder
���������������������padding
���color
���height
������������CurvedAnimation
���������
- ���������������������Singleton������������
3. ���������������
���������������������������������������������������������
- ������������������������������������
- ������������������������������������������������
- ���������������������������
StaggerAnimation
���������������������������������������
���������������������������������Flutter
���������������API���������������������������������������������������������������GestureRecognizer
���������������
发表评论
最新留言
网站不错 人气很旺了 加油
[***.192.178.218]2025年04月17日 06时54分31秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
web前端-CSS-媒体查询响应式和多列
2021-05-12
设计模式(18)——中介者模式
2021-05-12
用JavaScript实现希尔排序
2021-05-12
纯干货!深度分析一下AQS原理,一文全懂
2021-05-12
python初学者容易犯的错误
2021-05-12
Qt之QImage无法获取图片尺寸(宽和高)
2021-05-12
推荐几篇近期必看的视觉综述,含GAN、Transformer、人脸超分辨、遥感等
2021-05-12
Java-类加载过程
2021-05-12
BUU-MISC-认真你就输了
2021-05-12
BUU-MISC-caesar
2021-05-12
【专题2:电子工程师 之 上位机】 之 【36.事件重载】
2021-05-12
【专题3:电子工程师 之 上位机】 之 【46.QT音频接口】
2021-05-12
一文学会JVM常见参数设置+调优经验(JDK1.8)
2021-05-12
一文理解设计模式--命令模式(Command)
2021-05-12
VTK:可视化之RandomProbe
2021-05-12
block多队列分析 - 2. block多队列的初始化
2021-05-12
Java时间
2021-05-12
不编译只打包system或者vendor image命令
2021-05-12