Flutter 动画使用

旋转动画 
这里写图片描述 
透明度变换动画 
这里写图片描述

在Android中,可以通过View.animate()对视图进行动画处理,那在Flutter中怎样才能对Widget进行处理 
在Flutter中,可以通过动画库给widget添加动画。

在Android中,您可以通过XML创建动画或在视图上调用.animate()。在Flutter中,您可以将widget包装到Animation中。

与Android相似,在Flutter中,您有一个AnimationController和一个Interpolator, 它是Animation类的扩展,例如CurvedAnimation。您将控制器和动画传递到AnimationWidget中,并告诉控制器启动动画。

1import 'package:flutter/material.dart'; 2 3void main() { 4 runApp(new FadeAppTest()); 5} 6 7class FadeAppTest extends StatelessWidget { 8 @override 9 Widget build(BuildContext context) { 10 return new MaterialApp( 11 title: 'Fade Demo', 12 theme: new ThemeData( 13 primarySwatch: Colors.green, 14 ), 15 home: new MyFadeTest(title: 'Fade Demo'), 16 ); 17 } 18} 19 20class MyFadeTest extends StatefulWidget { 21 MyFadeTest({Key key, this.title}) : super(key: key); 22 final String title; 23 24 @override 25 State createState() => new _MyFadeTest(); 26} 27 28class _MyFadeTest extends State<MyFadeTest> with TickerProviderStateMixin { 29 AnimationController controller;//动画控制器 30 CurvedAnimation curved;//曲线动画,动画插值, 31 bool forward = true; 32 33 @override 34 void initState() {//初始化,当当前widget被插入到树中时调用 35 super.initState(); 36 controller = new AnimationController( 37 vsync: this, duration: const Duration(seconds: 3)); 38 curved = new CurvedAnimation(parent: controller, curve: Curves.bounceOut);//模仿小球自由落体运动轨迹 39// controller.forward();//放在这里开启动画 ,打开页面就播放动画 40 } 41 42 @override 43 Widget build(BuildContext context) { 44 return new Scaffold( 45 appBar: new AppBar( 46 title: new Text('FadeTest'), 47 ), 48 body: new Center( 49// child: new FadeTransition(//透明度动画 50// opacity: curved,//将动画传入不同的动画widget 51// child: new FlutterLogo(//创建一个小部件,用于绘制Flutter徽标 52// size: 200.0, 53// ), 54// ), 55 child: new RotationTransition(//旋转动画 56 turns: curved, 57 child: new FlutterLogo( 58 size: 200.0, 59 ), 60 61 ), 62 63 ), 64 floatingActionButton: new FloatingActionButton( 65 onPressed: () { 66 if (forward) 67 controller.forward();//向前播放动画 68 else 69 controller.reverse();//向后播放动画 70 forward = !forward; 71 }, 72 tooltip: 'fade', 73 child: new Icon(Icons.track_changes), 74 ), 75 ); 76 } 77}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

SpringBoot整合Redis乱码原因及解决方案

问题描述:springboot使用springdataredis存储数据时乱码rediskey/value出现\\xAC\\xED\\x00\\x05t\\x00\\x05问题分析:查看RedisTemplate类!(https://oscimg.oschina.net/oscnet/0a85565fa