import 'package:flutter/material.dart';
import 'dart:io';
import 'dart:async'; main() => runApp(MyApp()); class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: '/slide',
routes: {
'/': (context) => GamePage(),
'/builderAnimation': (context) => BuilderPage(),
'/crossfade': (context) => CrossFadePage(),
'/autofade': (context) => AutoFade(),
'/positiontransition': (context) => PositionTransition(),
'/rotateTransition': (context) => RotateTransition(),
'/scaleTransit': (context) => ScaleTest(),
'/slide': (context) => SlideTest(),
},
);
}
} ////////////////////////////////////////////////////////////////////////////////////////////////
class SlideTest extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return SlideTestState();
}
} class SlideTestState extends State<SlideTest> with SingleTickerProviderStateMixin{
@override
Widget build(BuildContext context) { var t = Tween(begin: Offset(0.0,2.0), end: Offset(0.0,1.0)).animate(AnimationController(vsync: this, duration: Duration(seconds: 2))..forward()); return Scaffold(
appBar: AppBar(title: Text('slide'),),
body: Container(
child: SlideTransition(
child: Container(width: 100,height: 100,color: Colors.orange,),
position: t),
),
);
}
} //////////////////////////////////////////////////////////////////////////////////////////////// class ScaleTest extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return ScaleTransitionState();
}
} class ScaleTransitionState extends State<ScaleTest> with SingleTickerProviderStateMixin{
@override
Widget build(BuildContext context) { Animation t = Tween(begin: 1.0, end: 0.0).animate(AnimationController(vsync: this,duration: Duration(seconds: 2))..forward()); return Scaffold(
appBar: AppBar(title: Text('scale'),),
body: Container(
child: ScaleTransition(
child: Container(width: 100,height: 100,color: Colors.orange,),
scale: t,), ),
);
}
} ////////////////////////////////////////////////////////////////////////////////////////////////
class RotateTransition extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return RotateTransitionState();
}
} class RotateTransitionState extends State<RotateTransition> with SingleTickerProviderStateMixin{
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('rotate'),),
body: Container(
child: RotationTransition(
child: Container(width: 100, height: 100, color: Colors.orange,),
turns: AnimationController(vsync: this,
duration: Duration(seconds: 1),lowerBound: 0, upperBound: 0.1)..forward(), ),
),
);
}
} ////////////////////////////////////////////////////////////////////////////////////////////////
class PositionTransition extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return PositionTransitionState();
}
} class PositionTransitionState extends State<PositionTransition> with SingleTickerProviderStateMixin { @override
Widget build(BuildContext context) { Animatable animatable = RelativeRectTween(begin: RelativeRect.fromLTRB(75, 75, 75, 75),
end: RelativeRect.fromLTRB(100, 100, 75, 75),);
Animation frontRelativeRect = animatable.animate(AnimationController(vsync: this, duration: Duration(seconds: 2))..repeat()); return Scaffold(
appBar: AppBar(title: Text('position transition'),),
body: Container(
child: Stack(
alignment: Alignment.center,
fit: StackFit.loose,
children: <Widget>[
Container(width: 200,height: 200,color: Colors.blue,),
Container(width: 100,height: 100,color: Colors.red,),
PositionedTransition(
rect: frontRelativeRect,
child: Container(width: 100,height: 100, color: Colors.orange,),
),
],
),
),
);
}
} //////////////////////////////////////////////////////////////////////////////////////////////// class AutoFade extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return AutoFadeState();
}
} class AutoFadeState extends State<AutoFade> with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('fade'),),
body: Container(
child: FadeTransition(
opacity: AnimationController(
vsync: this,
duration: Duration(seconds: 1),
)..repeat(),
child: Text(('testing auto fade')),
alwaysIncludeSemantics: true,
),
),
);
}
} ////////////////////////////////////////////////////////////////////////////////////////////////
class CrossFadePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return CrossFadePageState();
}
} class CrossFadePageState extends State<CrossFadePage> {
bool first = true; @override
Widget build(BuildContext context) {
Timer(Duration(seconds: 2), (){
setState(() {
first = !first;
});
});
return Scaffold(
appBar: AppBar(title: Text('fade'),),
body: AnimatedCrossFade(
firstChild: Text('first'),
secondChild: Text('second'),
crossFadeState: first?CrossFadeState.showFirst:CrossFadeState.showSecond,
duration: Duration(seconds: 1)),
);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
class BuilderPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return BuilderPageState();
}
} class BuilderPageState extends State<BuilderPage> with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
var controller = AnimationController(duration: Duration(seconds: 2),vsync: this);
var tween = Tween(begin: 20.0, end: 100.0).animate(controller);
return Scaffold(
appBar: AppBar(title: Text('fade'),),
body: AnimatedBuilder(
animation: tween,
child:Text('${tween.value}'),
builder: (context, Widget child){
print(controller.value);
print(tween.value);
return Container(
child: Column(
children: <Widget>[
RaisedButton(child: Text('btn'),onPressed: (){
controller.forward();
},),
Text('${tween.value} from 2'),
child,
],
),
);
}),
);
}
} //////////////////////////////////////////////////////////////////////////////////////////////// class GamePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return GamePageState();
}
} class GamePageState extends State<GamePage> with TickerProviderStateMixin {
var gameWidth;
var gameHeight;
var brickSide;
List positionedWidgets = [<Widget>[], <Widget>[], <Widget>[], <Widget>[]];
var animation; AnimationController animationController; generatePositionList() {
var top = (gameHeight - gameWidth) / 2.0 + 10.0;
var left = 10.0;
int i = 1;
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 4; x++) {
positionedWidgets[y].add(Brick(
id: i,
x: left + (1 + x * 2) * brickSide / 2.0,
y: top + (1 + y * 2) * brickSide / 2.0,
brickSide: brickSide,
value: x + y,
));
i++;
}
}
} @override
void initState() {
super.initState();
animationController = AnimationController(
vsync: this, duration: Duration(seconds: 1));
} @override
Widget build(BuildContext context) {
gameWidth = MediaQuery.of(context).size.width;
gameHeight = MediaQuery.of(context).size.height;
brickSide = (gameWidth - 80) / 4;
generatePositionList(); return SafeArea(
child: Scaffold(
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
child: Text(
'GAME 2048',
style: TextStyle(fontSize: 40),
),
), TouchArea(allBricks: positionedWidgets,), Container(
child: Text(
'SCORE:999',
style: TextStyle(fontSize: 20),
),
),
],
),
),
),
);
}
} class TouchArea extends StatefulWidget {
List allBricks;
TouchArea({this.allBricks}); @override
State<StatefulWidget> createState() {
return TouchAreaState();
}
} class TouchAreaState extends State<TouchArea> { @override
Widget build(BuildContext context) {
return GestureDetector(
child: Container(
margin:
EdgeInsets.only(left: 18, right: 18, top: 13, bottom: 13),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey, width: 3.0),
),
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: widget.allBricks[0],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: widget.allBricks[1],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: widget.allBricks[2],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: widget.allBricks[3],
),
],
),
),
);
}
} class Brick extends StatefulWidget {
double x;
double y;
var brickSide;
int value;
int id; Brick({this.id, this.x, this.y, this.brickSide, this.value}); @override
State<StatefulWidget> createState() {
return BrickState();
}
} class BrickState extends State<Brick> {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(2.0),
alignment: Alignment.center,
color: Colors.greenAccent,
width: widget.brickSide,
height: widget.brickSide,
child: Text('${widget.value}'),
);
}
} //class BrickState extends State<Brick>{
// @override
// Widget build(BuildContext context) {
// return Positioned(
// left: widget.x-widget.brickSide/2.0,top: widget.y-widget.brickSide/2.0,width: widget.brickSide,height: widget.brickSide,
// child: Container(child: Text('${widget.value}'),),
// );
// }
//}

  

flutter 动画 practice的更多相关文章

  1. 转:Flutter动画二

    1. 介绍 本文会从代码层面去介绍Flutter动画,因此不会涉及到Flutter动画的具体使用. 1.1 Animation库 Flutter的animation库只依赖两个库,Dart库以及phy ...

  2. 转:Flutter动画一

    1. 动画介绍 动画对于App来说,非常的重要.很多App,正是因为有了动画,所以才会觉得炫酷.移动端的动画库有非常的多,例如iOS上的Pop.web端的animate.css.Android端的An ...

  3. Flutter 动画详解(一)

    本文主要介绍了动画的原理相关概念,对其他平台的动画做了一个简要的梳理,并简要的介绍了Flutter动画的一些知识. 1. 动画介绍 动画对于App来说,非常的重要.很多App,正是因为有了动画,所以才 ...

  4. 《Flutter 动画系列一》25种动画组件超全总结

    动画运行的原理 任何程序的动画原理都是一样的,即:视觉暂留,视觉暂留又叫视觉暂停,人眼在观察景物时,光信号传入大脑神经,需经过一段短暂的时间,光的作用结束后,视觉形象并不立即消失,这种残留的视觉称&q ...

  5. 《Flutter 动画系列》组合动画

    老孟导读:在前面的文章中介绍了 <Flutter 动画系列>25种动画组件超全总结 http://laomengit.com/flutter/module/animated_1/ < ...

  6. Flutter 动画使用

    旋转动画  透明度变换动画  在Android中,可以通过View.animate()对视图进行动画处理,那在Flutter中怎样才能对Widget进行处理 在Flutter中,可以通过动画库给wid ...

  7. Flutter 动画鼻祖之CustomPaint

    老孟导读:CustomPaint可以称之为动画鼻祖,它可以实现任何酷炫的动画和效果.CustomPaint本身没有动画属性,仅仅是绘制属性,一般情况下,CustomPaint会和动画控制配合使用,达到 ...

  8. flutter 动画双指放大图片

    class GridAnimation extends StatefulWidget { @override State<StatefulWidget> createState() { r ...

  9. flutter 动画

    AnimatedCrossFade AnimatedCrossFade让俩个子widget 交替淡入淡出. class AnimatedCrossFade1 extends StatefulWidge ...

随机推荐

  1. 浅析package.json中的devdependencies 和 dependencies

    2.devDependencies (1)内容:是一个对象,配置模块依赖的模块列表,key是模块名称,value是版本范围(2)作用:该模块中所列举的插件属于开发环境的依赖(比如:测试或者文档框架等) ...

  2. SQL Server 变量定义

    declare @id intdeclare @name char(10) --注意:char(10)为10位,要是位数小了会让数据出错set @id=1 set @name='sssss'selec ...

  3. window 10 打开某个 窗口常用命令

    1. ctrl +R ,输入:inetcpl.cpl 2. ctrl +R ,输入:services.msc 3. ctrl +R ,输入:msconfig 安装双系统,设置开机引导 4. ctrl ...

  4. TeslaManage 运行日志

    “TeslaManage.exe”(Win32): 已加载“F:\TeslaManageProject\TeslaManage\x64\Debug\TeslaManage.exe”.已加载符号.“Te ...

  5. C++使用fill初始化二维数组

    类似如下用法: fill(dis[0], dis[0]+maxn*maxn, INF); 因为 dis[0]才是dis的首元素 dis[0][0] 的地址.

  6. MongoDB的局域网连接问题

    问题前两天在本机连接虚拟机的MongoDB,总是连接拒绝 上网百度了一堆,找到一些看似解释,实则不一定管用的玩意. 自己找到一个解法是改etc/mongodb.conf文件,把bindIp的127.0 ...

  7. elasticsearch的数据写入流程及优化

    Elasticsearch 写入流程及优化 一. 集群分片设置:ES一旦创建好索引后,就无法调整分片的设置,而在ES中,一个分片实际上对应一个lucene 索引,而lucene索引的读写会占用很多的系 ...

  8. 解决Python模块报错:ModuleNotFoundError: No module name 'StringIO'

    下面是我在学习中遇到的问题,给大家分享一下:   ''' 这里是测试代码 '''# coding = utf-8from selenium import webdriverfrom selenium. ...

  9. php_mvc实现步骤七

    shop34-5-登录表单 登录功能分析 功能:登录表单 C控制器-动作 back后台admin控制器loginAction动作完成该功能. Application/back/controller/A ...

  10. 8、1 周末总结+Mongdb

    都说加一个Id 注解就行了,其实还要加一条数据测试表是否生成 这里我们探讨  数据库是谁,表是谁 数据库在mongo启动的时候就指定了,这个无需我们关心 表根据实体类自动生成, 1.pom.xml & ...